home *** CD-ROM | disk | FTP | other *** search
/ Delphi 2 - Developers' Solutions / Delphi 2 Developers' Solutions.iso / dds / chap03 / howto10 / drwsutl3.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  1996-03-06  |  126.2 KB  |  3,443 lines

  1. unit Drwsutl3;
  2.  
  3. interface
  4.  
  5. uses
  6.   SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
  7.   Forms, Dialogs, StdCtrls, Buttons, ExtCtrls, ShellAPI, FileCtrl, DRWSUtl1;
  8.  
  9. const
  10.   EOC_CHANGEDIR = 1;  { Error Operation Code for change directory failure }
  11.   EOC_SOURCECOPY = 2; { Error Operation Code for source copy failure      }
  12.   EOC_DESTCOPY = 3;   { Error Operation Code for destination copy failure }
  13.   EOC_DELETEFILE = 4; { Error Operation Code for file delete failure      }
  14.   EOC_DELETEDIR = 5;  { Error Operation Code for directory delete failure }
  15.   EOC_RENAMEFILE = 6; { Error Operation Code for renaming failure         }
  16.   EOC_MAKEDIR = 7;    { Error Operation Code for MkDir failure            }
  17.   EOC_SETATTR = 8;    { Error Operation Code for Set Attributes failure   }
  18.  
  19.   FAC_COPY = 1;       { File Action Code for recursive copying            }
  20.   FAC_MOVE = 2;       { File Action Code for recursive moving             }
  21.   FAC_DELETE = 3;     { File Action Code for recursive deletion           }
  22.  
  23.   KBMJ_SINGLE = 1;   { Keyboard mouse motion constant for single pixel moves }
  24.   KBMJ_SMALL = 10;    { Keyboard mouse motion constant for single pixel moves }
  25.   KBMJ_LARGE = 50;    { Keyboard mouse motion constant for single pixel moves }
  26.  
  27.   CR_KEYSET = 6; { ID for special keypress cursor }
  28.   CR_NULL = 7;   { ID for Null (blank) cursor     }
  29. type
  30.   { This is a descendant of TFileListbox }
  31.   { Which puts icons of files into the   }
  32.   { Objects array rather than the stand- }
  33.   { ard bitmaps.                         }
  34.   TIconFileListBox = class( TFileListBox )
  35.   public
  36.     { public methods and data }
  37.     procedure ReadFileNames; override;
  38.     function GetNextSelection( SourceDirectory : String;
  39.               var CurrentItem : Integer ) : String;
  40.     constructor Create(AOwner : TComponent); override; { override create    }
  41.     procedure TheDblClick( Sender : TObject );{ This holds override dblclick }
  42.   end;
  43.   TFileWorkBench = class( TComponent )
  44.   public
  45.     GlobalError        : Integer;  { This is used by FMXUCopyFile for er code }
  46.     GlobalErrorType    : Integer;  { This holds the Operation code            }
  47.     function ForceTrailingBackSlash( const TheFileName : String ) : String;
  48.     function StripNonRootTrailingBackSlash(
  49.               const TheFileName : String ) : String;
  50.     procedure GetFileAttributes( TheFile : String; var IsDirectory , IsArchive ,
  51.                 IsVolumeID , IsHidden , IsReadOnly , IsSysFile : Boolean );
  52.     procedure HandleIOException( TheOpCode : Integer; ThePath : String;
  53.                                  TheMessage : String; TheCode : Integer );
  54.     procedure HandleDOSError( TheOpCode : Integer; ThePath : String;
  55.                 TheCode : Integer );
  56.     function CopyFile( TargetPath ,
  57.                DestinationPath : String ) : Boolean;
  58.     procedure ChangeTheDirectory( NewPath : String );
  59.     procedure ChangeTheDriveAndDirectory( NewDrive : Integer );
  60.     procedure CopyTheFile( OldPath , NewPath : String );
  61.     procedure MoveTheFile( OldPath , NewPath : String );
  62.     procedure DeleteTheFile( ThePath : String );
  63.     procedure RenameTheFile( OldPath , NewName : String );
  64.     procedure CreateNewDirectory( NewPath : String );
  65.     procedure RemoveDirectory( ThePath : String );
  66.     procedure SetFileAttributes( TheFile  : String; TheAttributes : Integer );
  67.     procedure RecursivelyCopyDirectory( OldPath , NewPath : String );
  68.     procedure RecursivelyMoveDirectory( OldPath , NewPath : String );
  69.     procedure RecursivelyDeleteDirectory( ThePath : String );
  70.     procedure HandleRecursiveAction( StartingPath , NewPath : String;
  71.                ActionCode : Integer );
  72.   end;
  73.   TFileIconPanel = class( TPanel )
  74.   private
  75.     { Private declarations }
  76.     FHighlightColor : TColor;                 { This holds bright edge bevel }
  77.     FShadowColor    : TColor;                 { This holds dark edge bevel   }
  78.     procedure TheMouseDown(Sender: TObject;
  79.       Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
  80.     procedure TheMouseMove( Sender: TObject; Shift: TShiftState;
  81.       X, Y: Integer);
  82.     procedure TheMouseUp(Sender: TObject;
  83.       Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
  84.     procedure WMLButtonDblClk(var Message: TWMLButtonDblClk);
  85.      message WM_LBUTTONDBLCLK;
  86.     procedure TheDragOver(Sender, Source: TObject; X,
  87.       Y: Integer; State: TDragState; var Accept: Boolean);
  88.     procedure TheDragDrop(Sender, Source: TObject; X,
  89.       Y: Integer);
  90.   protected                                   { event method procedure.      }
  91.     { Protected declarations }
  92.     procedure Paint; override;                { This allows custom painting  }
  93.   public
  94.     { Public declarations }
  95.     FTheIcon : TIcon;                         { This is the display icon    }
  96.     FTheName : String;                        { This is the filename        }
  97.     FTheLabel : TLabel;                       { This is the display label   }
  98.     Selected : Boolean;                       { This holds selection status }
  99.     constructor Create(AOwner : TComponent); override; { override create    }
  100.     procedure Initialize( PanelX              ,             { Left          }
  101.                           PanelY              ,             { Top           }
  102.                           PanelWidth          ,             { Width         }
  103.                           PanelHeight         ,             { Height        }
  104.                           PanelBevelWidth     ,             { Bevel Width   }
  105.                           LabelFontSize         : Integer;  { Font size     }
  106.                           PanelColor          ,             { Main color    }
  107.                           PanelHighlightColor ,             { Bright color  }
  108.                           PanelShadowColor    ,             { Dark color    }
  109.                           LabelTextColor        : TColor;   { Text color    }
  110.                           TheFilename         ,             { Filename      }
  111.                           LabelFontName         : String;   { Font name     }
  112.                           LabelFontStyle        : TFontStyles;  { Font style}
  113.                           ExtraData             : Integer       );  { Drive }
  114.     destructor Destroy; override;             { override destroy to free    }
  115.   end;
  116.   TFileIconPanelScrollBox = class( TScrollBox )
  117.   public
  118.     { Public methods and data }
  119.     TheFWB              : TFileWorkBench; { Used for file manipulation         }
  120.     IconsNeedRefreshing : Boolean;                   { Flag to redo display    }
  121.     TheIconSize        : Integer;   { Holds Individual Icon size               }
  122.     TheIconSpacing     : Integer;   { Holds total icon footprint               }
  123.     MaxIconsInARow     : Integer;   { Set for screen size.                     }
  124.     TheStoredHandle    : HWnd;
  125.     TheParentForm      : TForm;
  126.     procedure Update;                                { Called to reset display }
  127.     constructor Create( AOwner : TComponent ); override;  { Override inherited }
  128.     procedure ClearTheFIPs;                          { Clears the FIPs safely  }
  129.     procedure AddDriveIcons( var XCounter , YCounter : Integer ); { Add drives }
  130.     procedure GetColorsForFileIcon( TheFile : String;
  131.                var BC , HC , SC , TC : TColor );
  132.     procedure GetIconsForEntireDirectory( TargetPath  : String );
  133.     function GetNextSelection( SourceDirectory : String;
  134.               var CurrentItem : Integer ) : String;
  135.     procedure DisplayRecursiveSearchResults(
  136.       TheStartingDirectory : String );
  137.   end;
  138.   TIOManager = class( TComponent )
  139.   public
  140.     Parent : TForm;
  141.     WhichButton : TMouseButton;
  142.     WhichState  : TShiftState;
  143.     CLState ,
  144.     NLState ,
  145.     SLState   : Boolean;
  146.     function IsCapsLockDown : Boolean;
  147.     function ISNumLockDown : Boolean;
  148.     function IsScrollLockDown : Boolean;
  149.     procedure InitLocks;
  150.     procedure ReadLocks( var TheCL , TheNL , TheSL : Boolean );
  151.     procedure SetLocks( TheCL , TheNL , TheSL : Boolean );
  152.     function WasLeftPressed : Boolean;
  153.     function WasRightPressed : Boolean;
  154.     function WasMiddlePressed : Boolean;
  155.     function WasALTPressed : Boolean;
  156.     function WasSHIFTPressed : Boolean;
  157.     function WasCTRLPressed : Boolean;
  158.     procedure OnF1Pressed(Sender: TObject; var Key: Word;
  159.      Shift: TShiftState);
  160.     procedure OnF2Pressed(Sender: TObject; var Key: Word;
  161.      Shift: TShiftState);
  162.     procedure OnF3Pressed(Sender: TObject; var Key: Word;
  163.      Shift: TShiftState);
  164.     procedure OnF4Pressed(Sender: TObject; var Key: Word;
  165.      Shift: TShiftState);
  166.     procedure OnF5Pressed(Sender: TObject; var Key: Word;
  167.      Shift: TShiftState);
  168.     procedure OnF6Pressed(Sender: TObject; var Key: Word;
  169.      Shift: TShiftState);
  170.     procedure OnF7Pressed(Sender: TObject; var Key: Word;
  171.      Shift: TShiftState);
  172.     procedure OnF8Pressed(Sender: TObject; var Key: Word;
  173.      Shift: TShiftState);
  174.     procedure OnF9Pressed(Sender: TObject; var Key: Word;
  175.      Shift: TShiftState);
  176.     procedure OnF10Pressed(Sender: TObject; var Key: Word;
  177.      Shift: TShiftState);
  178.     procedure OnF11Pressed(Sender: TObject; var Key: Word;
  179.      Shift: TShiftState);
  180.     procedure OnF12Pressed(Sender: TObject; var Key: Word;
  181.      Shift: TShiftState);
  182.  end;
  183.  TMouseManager = class( TComponent )
  184.  public
  185.    TheMX : Integer;
  186.    TheMY : Integer;
  187.    Old_X ,
  188.    Old_Y ,
  189.    New_X ,
  190.    New_Y   : Integer;
  191.    StoredCursor : Integer;
  192.    BitmapCursor  : Boolean;
  193.    IconCursor    : Boolean;
  194.    CursorBMP     : TBitmap;
  195.    CursorIcon    : TIcon;
  196.    IsAnimated    : Boolean;
  197.    TheTimer      : TTimer;
  198.    TheAnimationList : TList;
  199.    CurrentAnimationPointer : Integer;
  200.    AnimationInterval : Integer;
  201.    SavedDC ,
  202.    GlobalDC : HDC;
  203.    GlobalCanvas : TCanvas;
  204.    WorkSpaceBMP : TBitmap;
  205.    BackGroundBMP : TBitmap;
  206.    constructor Create( AOwner : TComponent ); override;
  207.    destructor Destroy; override;
  208.    procedure InitializeNormal;
  209.    procedure InitializeBitmap( TheBmp : TBitmap );
  210.    procedure InitializeIcon( TheIcon : TIcon );
  211.    procedure InitializeAnimated( TheIcon : TIcon; TheInterval : Integer;
  212.                                  TheIconList : TList );
  213.    procedure GetMousePosition( var MouseX , MouseY : Integer );
  214.    procedure SetMousePosition( MouseX , MouseY : Integer );
  215.    procedure MoveSinglePixelLeft;
  216.    procedure MoveSinglePixelRight;
  217.    procedure MoveSinglePixelUp;
  218.    procedure MoveSinglePixelDown;
  219.    procedure MoveSmallJumpLeft;
  220.    procedure MoveSmallJumpRight;
  221.    procedure MoveSmallJumpUp;
  222.    procedure MoveSmallJumpDown;
  223.    procedure MoveLargeJumpLeft;
  224.    procedure MoveLargeJumpRight;
  225.    procedure MoveLargeJumpUp;
  226.    procedure MoveLargeJumpDown;
  227.    procedure StartBitmapCursor( TheX , TheY : Integer );
  228.    procedure MoveBitmapCursor( TheX , TheY : Integer );
  229.    procedure EndBitmapCursor( TheX , TheY : Integer );
  230.    procedure StartIconCursor( TheX , TheY : Integer );
  231.    procedure MoveIconCursor( TheX , TheY : Integer );
  232.    procedure EndIconCursor( TheX , TheY : Integer );
  233.    procedure StartAnimatedIconCursor( TheX , TheY : Integer );
  234.    procedure EndAnimatedIconCursor( TheX , TheY : Integer );
  235.    procedure MoveAnimatedIconCursor( TheX , TheY : Integer );
  236.    procedure TimerAction( Sender : TObject );
  237.  end;
  238.  
  239.   { This procedure gets an icon for a file using FindExecutable  }
  240.   { and ExtractIcon. (assumes file/dir is passed)                }
  241.   procedure GetIconForFile( TheName : String; var TheIcon : TIcon );
  242.   { This procedure spaces out the bitbtn components on a tpanel }
  243.   procedure SpacePanelButtons( WhichPanel : TPanel );
  244.     procedure FMXUCopyFile(const FileName, DestName: String; var GlobalErrorType ,
  245.                GlobalErrorCode : Integer );
  246.  
  247. var TheIOManager : TIOManager;
  248.     TheMouseManager : TMouseManager;
  249.     GlobalAbortFlag : Boolean;
  250.     SavedForm : TForm;
  251.     SavedControl : TFileIconPanel;
  252.     OtherSavedControl : TFileIconPanelScrollbox;
  253.     Savedhandle : HWnd;
  254.     IconDragging : boolean;
  255.     GlobalSource : TObject;
  256.     TheTempBitmap : TBitmap;
  257.     BitmapDragging : boolean;
  258.  
  259. implementation
  260. {$R DRWSUTL3.RES}                 { Import custom resource file }
  261. uses UFMGR19;
  262.  
  263. { It has been edited to return viable error codes!             }
  264. procedure FMXUCopyFile(const FileName, DestName: String; var GlobalErrorType ,
  265.             GlobalErrorCode : Integer );
  266. var
  267.   CopyBuffer: Pointer; { buffer for copying }
  268.   BytesCopied: Longint;
  269.   TheAttr : Integer;
  270.   Source, Dest: Integer; { handles }
  271. const
  272.   ChunkSize: Longint = 8192; { copy in 8K chunks }
  273. begin
  274.   GetMem(CopyBuffer, ChunkSize); { allocate the buffer }
  275.   Source := FileOpen(FileName, fmShareDenyWrite); { open source file }
  276.   if Source < 0 then
  277.   begin  { error creating source file }
  278.     GlobalErrorType := EOC_SOURCECOPY;
  279.     GlobalErrorCode := -IOResult;
  280.     if GlobalErrorCode = 0 then GlobalErrorCode := -157;
  281.     FreeMem( CopyBuffer, ChunkSize );
  282.     exit;
  283.   end;
  284.   Dest := FileCreate(DestName); { create output file; overwrite existing }
  285.   if Dest < 0 then
  286.   begin  { error creating destination file }
  287.     FileClose( Source );
  288.     GlobalErrorType := EOC_DESTCOPY;
  289.     GlobalErrorCode := -IOResult;
  290.     if GlobalErrorCode = 0 then GlobalErrorCode := -159;
  291.     FreeMem( CopyBuffer , ChunkSize );
  292.     exit;
  293.   end;
  294.   {$I-}
  295.   repeat
  296.     BytesCopied := FileRead(Source, CopyBuffer^, ChunkSize); { read chunk}
  297.     if BytesCopied > 0 then { if we read anything... }
  298.     FileWrite(Dest, CopyBuffer^, BytesCopied); { ...write chunk }
  299.   until BytesCopied < ChunkSize; { until we run out of chunks }
  300.   {$I+}
  301.   GlobalErrorCode := -IOResult;  { get any error code which happens during copying }
  302.   FileClose(Dest); { close the destination file }
  303.   FileClose(Source); { close the source file }
  304.   FreeMem(CopyBuffer, ChunkSize); { free the buffer }
  305. end;
  306.  
  307. { This procedure spaces out the bitbtn components on a tpanel }
  308. procedure SpacePanelButtons( WhichPanel : TPanel );
  309. var TheCalculatedSpacing     ,            { Holds primary spacing }
  310.     TheFullCalculatedSpacing   : Integer; { Holds full spacing    }
  311.     Counter_1                  : Integer; { Loop counter          }
  312.     TotalIBs                   : Integer; { Gets total buttons    }
  313. begin
  314.   { Set up spacing values }
  315.   TotalIBs := WhichPanel.ControlCount;
  316.   TheCalculatedSpacing := (( WhichPanel.Width - 6 - ( TotalIbs * 49 ))
  317.    div ( TotalIbs + 1 ));
  318.   TheFullCalculatedSpacing := TheCalculatedSpacing + 49;
  319.   { Loop through all imported buttons and set their Left values }
  320.   for Counter_1 := 1 to WhichPanel.ControlCount do
  321.   begin
  322.     if Counter_1 = 1 then
  323.     begin
  324.       TBitBtn( WhichPanel.Controls[ Counter_1 - 1 ] ).Left := 3 +
  325.        TheCalculatedSpacing;
  326.     end
  327.     else
  328.     begin
  329.       TBitBtn( WhichPanel.Controls[ Counter_1 - 1 ] ).Left := 3 +
  330.        (( Counter_1 - 1 ) * TheFullCalculatedSpacing ) + TheCalculatedSpacing;
  331.     end;
  332.   end;
  333. end;
  334.  
  335. { This procedure gets an icon for a file using FindExecutable  }
  336. { and ExtractIcon. (assumes file/dir is passed)                }
  337. procedure GetIconForFile( TheName : String; var TheIcon : TIcon );
  338. var TheExt           : String; { File extension holder }
  339.     TheOtherPChar  ,           { Windows ASCIIZ string }
  340.     ThePChar         : PChar;  { Windows ASCIIZ string }
  341.     Dummy : Word;
  342. begin
  343.   { Check for directory and if so get directory icon from RES file }
  344.   if (( FileGetAttr( TheName ) and faDirectory ) = faDirectory ) then
  345.   begin
  346.     { Set up the PChar to communicate with Windows }
  347.     GetMem( TheOtherPChar , 255 );
  348.     { Convert Pascal-style string to ASCIIZ Pchar }
  349.     StrPCopy( TheOtherPChar , 'DIRECTORY' );
  350.     { Use API call to return icon handle of Icon Resource in FILECTRL.RES }
  351.     TheIcon.Handle := LoadIcon( hInstance , TheOtherPChar );
  352.     { Release memory from PChar }
  353.     FreeMem( TheOtherPChar , 255 );
  354.     { Leave }
  355.     exit;
  356.   end;
  357.   { Assume archive file; get its extension }
  358.   TheExt := Uppercase( ExtractFileExt( TheName ));
  359.   { If not an executable/image file then use FindExecutable to get icon }
  360.   if (( TheExt <> '.EXE' ) and ( TheExt <> '.BAT' ) and
  361.       ( TheExt <> '.PIF' ) and ( TheExt <> '.COM' )) then
  362.   begin
  363.     { Grab three chunks of memory }
  364.     GetMem( ThePChar , 255 );
  365.     { Set up the name and its directory in Windows string formats }
  366.     StrPCopy( ThePChar, TheName );
  367.     Dummy := 65535;
  368.     {**** Windows 95 Specialized call ****** }
  369.     TheIcon.Handle := ExtractAssociatedIcon( hInstance , ThePChar , Dummy );
  370.     if TheIcon.Handle = 0 then
  371.     begin
  372.       GetMem( TheOtherPChar , 255 );
  373.       StrPCopy( TheOtherPChar , 'NOICON' );
  374.       TheIcon.Handle := LoadIcon( hInstance , TheOtherPChar );
  375.       FreeMem( TheOtherPChar , 255 );
  376.       exit;
  377.     end;
  378.     FreeMem( ThePChar , 255 );
  379.   end
  380.   else
  381.   { Assume Windows Executable file, so get icon from it with ExtractIcon API }
  382.   begin
  383.     GetMem( ThePChar , 255 );
  384.     StrPCopy( ThePChar , TheName );
  385.     { Try to get first icon for file }
  386.     Dummy := 65535;
  387.     TheIcon.Handle := ExtractAssociatedIcon( hInstance , ThePChar , Dummy );
  388.     FreeMem( ThePChar , 255 );
  389.     { If handle is 0 invalid icon format so use default from RES file }
  390.     if TheIcon.Handle = 0 then
  391.     begin
  392.       GetMem( TheOtherPChar , 255 );
  393.       StrPCopy( TheOtherPChar , 'NOICON' );
  394.       TheIcon.Handle := LoadIcon( hInstance , TheOtherPChar );
  395.       FreeMem( TheOtherPChar , 255 );
  396.       exit;
  397.     end;
  398.   end;
  399. end;
  400.  
  401.  
  402. { This creates the TMouseManager and inits vars to null }
  403. constructor TMouseManager.Create( AOwner : TComponent );
  404. begin
  405.   { Call inherited FIRST! }
  406.   inherited Create( AOwner );
  407.   { Set all variables to 0 , false or nil }
  408.   TheMX := 0;
  409.   TheMY := 0;
  410.   Old_X  := 0;
  411.   Old_Y  := 0;
  412.   New_X  := 0;
  413.   New_Y  := 0;
  414.   StoredCursor := 0;
  415.   BitmapCursor  := false;
  416.   IconCursor    := false;
  417.   CursorBMP     := nil;
  418.   CursorIcon    := nil;
  419.   IsAnimated    := false;
  420.   TheTimer      := nil;
  421.   TheAnimationList := nil;
  422.   CurrentAnimationPointer := 0;
  423.   AnimationInterval := 0;
  424.   SavedDC := 0;
  425.   GlobalDC := 0;
  426.   GlobalCanvas := nil;
  427.   WorkSpaceBMP := nil;
  428.   BackGroundBMP := nil;
  429. end;
  430.  
  431. { This destroys the tmousemanager and releases all resources }
  432. destructor TMouseManager.Destroy;
  433. begin
  434.   { Free any assigned resources (the moving bmp ones already are gone) }
  435.   if assigned( TheTimer ) then
  436.    TheTimer.Free;
  437.   if assigned( TheAnimationList ) then
  438.    TheAnimationList.Free;
  439.   Inherited Destroy;
  440. end;
  441.  
  442. { This sets up the mouse manager for normal cursor operations }
  443. procedure TMouseManager.InitializeNormal;
  444. var TheMP : TPoint;
  445. begin
  446.   { Reset State Variables }
  447.   BitmapCursor := false;
  448.   IconCursor := false;
  449.   IsAnimated := false;
  450.   { Call API to get mouse coordinates }
  451.   GetCursorPos( TheMP );
  452.   { Store the coordinates for later use }
  453.   TheMX := TheMP.X;
  454.   TheMY := TheMP.Y;
  455.   Old_X := TheMX;
  456.   Old_Y := TheMY;
  457.   New_X := TheMX;
  458.   New_Y := TheMY;
  459. end;
  460.  
  461. { This procedure initializes a bitmap cursor }
  462. procedure TMouseManager.InitializeBitmap( TheBmp : TBitmap );
  463. begin
  464.   InitializeNormal;
  465.   CursorBMP := TheBMP;
  466.   BitmapCursor := true;
  467. end;
  468.  
  469. { This procedure initalizes an icon cursor }
  470. procedure TMouseManager.InitializeIcon( TheIcon : TIcon );
  471. begin
  472.   InitializeNormal;
  473.   CursorIcon := TheIcon;
  474.   IconCursor := true;
  475. end;
  476.  
  477. { This procedure initializes an animated icon cursor }
  478. procedure TMouseManager.InitializeAnimated( TheIcon : TIcon;
  479.            TheInterval : Integer; TheIconList : TList );
  480. begin
  481.   InitializeNormal;
  482.   CursorIcon := TheIcon;
  483.   IconCursor := true;
  484.   IsAnimated := true;
  485.   AnimationInterval := TheInterval;
  486.   TheAnimationList := TheIconList;
  487.   TheTimer := TTimer.Create( Self );
  488.   TheTimer.Enabled := false;
  489.   TheTimer.Interval := AnimationInterval;
  490.   TheTimer.OnTimer := TimerAction;
  491. end;
  492.  
  493. { This procedure returns the current stored mouse position }
  494. procedure TMouseManager.GetMousePosition( var MouseX , MouseY : Integer );
  495. begin
  496.   { Return stored position rather than call API }
  497.   MouseX := TheMX;
  498.   MouseY := TheMY;
  499. end;
  500.  
  501. { This procedure sets the Mouse Position internally }
  502. procedure TMouseManager.SetMousePosition( MouseX , MouseY : Integer );
  503. begin
  504.   { Set internal coordinates; don't call API }
  505.   TheMX := MouseX;
  506.   TheMY := MouseY;
  507. end;
  508.  
  509. { This procedure is used to drive the mouse with the keyboard }
  510. procedure TMouseManager.MoveSinglePixelLeft;
  511. begin
  512.   { Use internal coordinates and check for screen wrapping }
  513.   if TheMX > KBMJ_SINGLE then
  514.   begin
  515.     { Not wrapped; move along one unit to the left }
  516.     TheMX := TheMX - KBMJ_SINGLE;
  517.     SetCursorPos( TheMX , TheMY );
  518.   end
  519.   else
  520.   begin
  521.     { Wrapped; jump to right and move back one unit }
  522.     TheMX := Screen.Width - KBMJ_SINGLE;
  523.     SetCursorPos( TheMX , TheMY );
  524.   end;
  525. end;
  526.  
  527. { This procedure is used to drive the mouse with the keyboard }
  528. procedure TMouseManager.MoveSinglePixelRight;
  529. begin
  530.   { Use internal coordinates and check for screen wrapping }
  531.   if TheMX < ( Screen.Width - KBMJ_SINGLE ) then
  532.   begin
  533.     { Not wrapped; move along one unit to the right }
  534.     TheMX := TheMX + KBMJ_SINGLE;
  535.     SetCursorPos( TheMX , TheMY );
  536.   end
  537.   else
  538.   begin
  539.     { Wrapped; jump to left and move in one unit }
  540.     TheMX := KBMJ_SINGLE;
  541.     SetCursorPos( TheMX , TheMY );
  542.   end;
  543. end;
  544.  
  545. { This procedure is used to drive the mouse with the keyboard }
  546. procedure TMouseManager.MoveSinglePixelUp;
  547. begin
  548.   { Use internal coordinates and check for screen wrapping }
  549.   if TheMY > KBMJ_SINGLE then
  550.   begin
  551.     { Not wrapped; move along one unit to the top }
  552.     TheMY := TheMY - KBMJ_SINGLE;
  553.     SetCursorPos( TheMX , TheMY );
  554.   end
  555.   else
  556.   begin
  557.     { Wrapped; jump to bottom and move back one unit }
  558.     TheMY := Screen.Height - KBMJ_SINGLE;
  559.     SetCursorPos( TheMX , TheMY );
  560.   end;
  561. end;
  562.  
  563. { This procedure is used to drive the mouse with the keyboard }
  564. procedure TMouseManager.MoveSinglePixelDown;
  565. begin
  566.   { Use internal coordinates and check for screen wrapping }
  567.   if TheMY < ( Screen.Height - KBMJ_SINGLE ) then
  568.   begin
  569.     { Not wrapped; move along one unit to the bottom }
  570.     TheMY := TheMY + KBMJ_SINGLE;
  571.     SetCursorPos( TheMX , TheMY );
  572.   end
  573.   else
  574.   begin
  575.     { Wrapped; jump to top and move back one unit }
  576.     TheMY := KBMJ_SINGLE;
  577.     SetCursorPos( TheMX , TheMY );
  578.   end;
  579. end;
  580.  
  581. { This procedure is used to drive the mouse with the keyboard }
  582. procedure TMouseManager.MoveSmallJumpLeft;
  583. begin
  584.   { Use internal coordinates and check for screen wrapping }
  585.   if TheMX > KBMJ_SMALL then
  586.   begin
  587.     { Not wrapped; move along one unit to the left }
  588.     TheMX := TheMX - KBMJ_SMALL;
  589.     SetCursorPos( TheMX , TheMY );
  590.   end
  591.   else
  592.   begin
  593.     { Wrapped; jump to right and move back the unit }
  594.     TheMX := Screen.Width - KBMJ_SMALL;
  595.     SetCursorPos( TheMX , TheMY );
  596.   end;
  597. end;
  598.  
  599. { This procedure is used to drive the mouse with the keyboard }
  600. procedure TMouseManager.MoveSmallJumpRight;
  601. begin
  602.   { Use internal coordinates and check for screen wrapping }
  603.   if TheMX < ( Screen.Width - KBMJ_SMALL ) then
  604.   begin
  605.     { Not wrapped; move along one unit to the right }
  606.     TheMX := TheMX + KBMJ_SMALL;
  607.     SetCursorPos( TheMX , TheMY );
  608.   end
  609.   else
  610.   begin
  611.     { Wrapped; jump to left and move in one unit }
  612.     TheMX := KBMJ_SMALL;
  613.     SetCursorPos( TheMX , TheMY );
  614.   end;
  615. end;
  616.  
  617. { This procedure is used to drive the mouse with the keyboard }
  618. procedure TMouseManager.MoveSmallJumpUp;
  619. begin
  620.   { Use internal coordinates and check for screen wrapping }
  621.   if TheMY > KBMJ_SMALL then
  622.   begin
  623.     { Not wrapped; move along one unit to the top }
  624.     TheMY := TheMY - KBMJ_SMALL;
  625.     SetCursorPos( TheMX , TheMY );
  626.   end
  627.   else
  628.   begin
  629.     { Wrapped; jump to bottom and move back one unit }
  630.     TheMY := Screen.Height - KBMJ_SMALL;
  631.     SetCursorPos( TheMX , TheMY );
  632.   end;
  633. end;
  634.  
  635. { This procedure is used to drive the mouse with the keyboard }
  636. procedure TMouseManager.MoveSmallJumpDown;
  637. begin
  638.   { Use internal coordinates and check for screen wrapping }
  639.   if TheMY < ( Screen.Height - KBMJ_SMALL ) then
  640.   begin
  641.     { Not wrapped; move along one unit to the bottom }
  642.     TheMY := TheMY + KBMJ_SMALL;
  643.     SetCursorPos( TheMX , TheMY );
  644.   end
  645.   else
  646.   begin
  647.     { Wrapped; jump to top and move back one unit }
  648.     TheMY := KBMJ_SMALL;
  649.     SetCursorPos( TheMX , TheMY );
  650.   end;
  651. end;
  652.  
  653. { This procedure is used to drive the mouse with the keyboard }
  654. procedure TMouseManager.MoveLargeJumpLeft;
  655. begin
  656.   { Use internal coordinates and check for screen wrapping }
  657.   if TheMX > KBMJ_LARGE then
  658.   begin
  659.     { Not wrapped; move along the unit to the left }
  660.     TheMX := TheMX - KBMJ_LARGE;
  661.     SetCursorPos( TheMX , TheMY );
  662.   end
  663.   else
  664.   begin
  665.     { Wrapped; jump to right and move back the unit }
  666.     TheMX := Screen.Width - KBMJ_LARGE;
  667.     SetCursorPos( TheMX , TheMY );
  668.   end;
  669. end;
  670.  
  671. { This procedure is used to drive the mouse with the keyboard }
  672. procedure TMouseManager.MoveLargeJumpRight;
  673. begin
  674.   { Use internal coordinates and check for screen wrapping }
  675.   if TheMX < ( Screen.Width - KBMJ_LARGE ) then
  676.   begin
  677.     { Not wrapped; move along one unit to the right }
  678.     TheMX := TheMX + KBMJ_LARGE;
  679.     SetCursorPos( TheMX , TheMY );
  680.   end
  681.   else
  682.   begin
  683.     { Wrapped; jump to left and move in one unit }
  684.     TheMX := KBMJ_LARGE;
  685.     SetCursorPos( TheMX , TheMY );
  686.   end;
  687. end;
  688.  
  689. { This procedure is used to drive the mouse with the keyboard }
  690. procedure TMouseManager.MoveLargeJumpUp;
  691. begin
  692.   { Use internal coordinates and check for screen wrapping }
  693.   if TheMY > KBMJ_LARGE then
  694.   begin
  695.     { Not wrapped; move along one unit to the top }
  696.     TheMY := TheMY - KBMJ_LARGE;
  697.     SetCursorPos( TheMX , TheMY );
  698.   end
  699.   else
  700.   begin
  701.     { Wrapped; jump to bottom and move back one unit }
  702.     TheMY := Screen.Height - KBMJ_LARGE;
  703.     SetCursorPos( TheMX , TheMY );
  704.   end;
  705. end;
  706.  
  707. { This procedure is used to drive the mouse with the keyboard }
  708. procedure TMouseManager.MoveLargeJumpDown;
  709. begin
  710.   { Use internal coordinates and check for screen wrapping }
  711.   if TheMY < ( Screen.Height - KBMJ_LARGE ) then
  712.   begin
  713.     { Not wrapped; move along one unit to the bottom }
  714.     TheMY := TheMY + KBMJ_LARGE;
  715.     SetCursorPos( TheMX , TheMY );
  716.   end
  717.   else
  718.   begin
  719.     { Wrapped; jump to top and move back one unit }
  720.     TheMY := KBMJ_LARGE;
  721.     SetCursorPos( TheMX , TheMY );
  722.   end;
  723. end;
  724.  
  725. { This procedure sets up the bitmaps and global HDC prior to moving a }
  726. { Bitmap cursor.                                                      }
  727. procedure TMouseManager.StartBitmapCursor( TheX , TheY : Integer );
  728. var WorkingPoint1 ,
  729.     WorkingPoint2 : TPoint;
  730. begin
  731.   GlobalDC := GetDC( 0 );
  732.   WorkspaceBMP := TBitmap.Create;
  733.   WorkspaceBMP.Width := Screen.Width;
  734.   WorkSpaceBMP.Height := Screen.Height;
  735.   BitBlt( WorkspaceBMP.Canvas.Handle , 0 , 0 , Screen.Width , Screen.Height ,
  736.    GlobalDC , 0 , 0 , SrcCopy );
  737.   BackgroundBMP := TBitmap.Create;
  738.   BackgroundBMP.Width := CursorBMP.Width;
  739.   BackgroundBMP.Height := CursorBMP.Height;
  740.   New_X := TheX;
  741.   New_Y := TheY;
  742.   StoredCursor := Screen.Cursor;
  743.   Screen.Cursor := CR_NULL;
  744.   {Grab the background image}
  745.   WorkingPoint1.X := New_X - ( CursorBMP.Width div 2 );
  746.   WorkingPoint1.Y := New_Y - ( CursorBMP.Height div 2 );
  747.   WorkingPoint2.X := New_X + ( CursorBMP.Width - ( CursorBMP.Width div 2 ));
  748.   WorkingPoint2.Y := New_Y + ( CursorBMP.Height - ( CursorBMP.Height div 2 ));
  749.   BackgroundBmp.Canvas.CopyRect( Rect( 0 , 0 , CursorBMP.Width , CursorBMP.Height ) ,
  750.    WorkspaceBMP.Canvas , Rect( WorkingPoint1.X , WorkingPoint1.Y , WorkingPoint2.X ,
  751.     WorkingPoint2.Y ));
  752.   {Put the cursor bitmap onto the workspace canvas}
  753.   with WorkspaceBMP.Canvas do
  754.   begin
  755.     CopyMode := cmSrcCopy;
  756.     CopyRect( Rect( WorkingPoint1.X , WorkingPoint1.Y , WorkingPoint2.X , WorkingPoint2.Y ),
  757.      CursorBMP.Canvas , Rect( 0 , 0 , CursorBMP.Width , CursorBMP.Height ));
  758.   end;
  759.   {Copy the workspace bitmap onto the visible screen}
  760.     BitBlt( GlobalDC , WorkingPoint1.X , WorkingPoint1.Y , CursorBMP.Width , CursorBMP.Height ,
  761.      WorkspaceBMP.Canvas.Handle , WorkingPoint1.X , WorkingPoint1.Y , SrcCopy );
  762.   Old_X := New_X;
  763.   Old_Y := New_Y;
  764. end;
  765.  
  766. { This procedure moves a bitmap cursor according to the imported New coords }
  767. procedure TMouseManager.MoveBitmapCursor( TheX , TheY : Integer );
  768. var StartX,
  769.     StartY,
  770.     XDiff,
  771.     YDiff : Integer;
  772.     WorkingPoint1 ,
  773.     WorkingPoint2  : TPoint;
  774. begin
  775.   New_X := TheX;
  776.   New_Y := TheY;
  777.   WorkingPoint1.X := Old_X - ( CursorBMP.Width div 2 );
  778.   WorkingPoint1.Y := Old_Y - ( CursorBMP.Height div 2 );
  779.   WorkingPoint2.X := Old_X + ( CursorBMP.Width - ( CursorBMP.Width div 2 ));
  780.   WorkingPoint2.Y := Old_Y + ( CursorBMP.Height - ( CursorBMP.Height div 2 ));
  781.   with WorkspaceBMP.Canvas do
  782.   begin
  783.     CopyMode := cmSrcCopy;
  784.     CopyRect( Rect( WorkingPoint1.X , WorkingPoint1.Y , WorkingPoint2.X , WorkingPoint2.Y ),
  785.       BackgroundBMP.Canvas , Rect( 0 , 0 , CursorBMP.Width , CursorBMP.Height ));
  786.   end;
  787.   {Put the saved bitmap onto the workspace canvas}
  788.   with WorkspaceBMP.Canvas do
  789.   begin
  790.     CopyMode := cmSrcCopy;
  791.     CopyRect( Rect( WorkingPoint1.X , WorkingPoint1.Y , WorkingPoint2.X , WorkingPoint2.Y ),
  792.      BackgroundBMP.Canvas , Rect( 0 , 0 , CursorBMP.Width , CursorBMP.Height ));
  793.   end;
  794.   {Grab the background image}
  795.   WorkingPoint1.X := New_X - ( CursorBMP.Width div 2 );
  796.   WorkingPoint1.Y := New_Y - ( CursorBMP.Height div 2 );
  797.   WorkingPoint2.X := New_X + ( CursorBMP.Width - ( CursorBMP.Width div 2 ));
  798.   WorkingPoint2.Y := New_Y + ( CursorBMP.Height - ( CursorBMP.Height div 2 ));
  799.   BackgroundBmp.Canvas.CopyRect( Rect( 0 , 0 , CursorBMP.Width , CursorBMP.Height ) ,
  800.    WorkspaceBMP.Canvas , Rect( WorkingPoint1.X , WorkingPoint1.Y , WorkingPoint2.X ,
  801.     WorkingPoint2.Y ));
  802.   {Put the cursor bitmap onto the workspace canvas}
  803.   with WorkspaceBMP.Canvas do
  804.   begin
  805.     CopyMode := cmSrcCopy;
  806.     CopyRect( Rect( WorkingPoint1.X , WorkingPoint1.Y , WorkingPoint2.X , WorkingPoint2.Y ),
  807.      CursorBMP.Canvas , Rect( 0 , 0 , CursorBMP.Width , CursorBMP.Height ));
  808.   end;
  809.   {Copy the workspace bitmap onto the visible screen}
  810.   if New_X > Old_X then StartX := Old_X else StartX := New_X;
  811.   if New_Y > Old_Y then StartY := Old_Y else StartY := New_Y;
  812.   XDiff := Abs( Old_X - New_X );
  813.   YDiff := Abs( Old_Y - New_Y );
  814.   {Grab the background image}
  815.   WorkingPoint1.X := StartX - ( CursorBMP.Width div 2 );
  816.   WorkingPoint1.Y := StartY - ( CursorBMP.Height div 2 );
  817.   BitBlt( GlobalDC , WorkingPoint1.X , WorkingPoint1.Y , CursorBMP.Width + XDiff ,
  818.    CursorBMP.Height + YDiff , WorkspaceBMP.Canvas.Handle , WorkingPoint1.X ,
  819.     WorkingPoint1.Y , SrcCopy );
  820.   Old_X := New_X;
  821.   Old_Y := New_Y;
  822. end;
  823.  
  824. { This procedure releases a bitmap cursor and frees its DC }
  825. procedure TMouseManager.EndBitmapCursor( TheX , TheY : Integer );
  826. var WorkingPoint1 ,
  827.     WorkingPoint2 : TPoint;
  828. begin
  829.   BitmapCursor := false;
  830.   WorkingPoint1.X := Old_X - ( CursorBMP.Width div 2 );
  831.   WorkingPoint1.Y := Old_Y - ( CursorBMP.Height Div 2 );
  832.   WorkingPoint2.X := Old_X + ( CursorBMP.Width - ( CursorBMP.Width div 2 ));
  833.   WorkingPoint2.Y := Old_Y + ( CursorBMP.Height - ( CursorBMP.Height div 2 ));
  834.   {Put the saved bitmap onto the workspace canvas}
  835.   with WorkspaceBMP.Canvas do
  836.   begin
  837.     CopyMode := cmSrcCopy;
  838.     CopyRect( Rect( WorkingPoint1.X , WorkingPoint1.Y , WorkingPoint2.X , WorkingPoint2.Y ),
  839.        BackGroundBMP.Canvas , Rect( 0 , 0 , CursorBMP.Width ,  CursorBMP.Height ));
  840.   end;
  841.   {Copy the workspace bitmap onto the visible screen}
  842.   BitBlt( GlobalDC , WorkingPoint1.X , WorkingPoint1.Y , CursorBMP.Width , CursorBMP.Height ,
  843.    WorkspaceBMP.Canvas.handle , WorkingPoint1.X , WorkingPoint1.Y , SrcCopy );
  844.   ReleaseDC( 0 , GlobalDC );
  845.   Screen.Cursor := StoredCursor;
  846. end;
  847.  
  848. { This procedure starts the process of displaying an icon cursor }
  849. procedure TMouseManager.StartIconCursor( TheX , TheY : Integer );
  850. var WorkingPoint1 ,
  851.     WorkingPoint2 : TPoint;
  852. begin
  853.   GlobalDC := GetDC( 0 );
  854.   WorkspaceBMP := TBitmap.Create;
  855.   WorkspaceBMP.Width := Screen.Width;
  856.   WorkSpaceBMP.Height := Screen.Height;
  857.   BitBlt( WorkspaceBMP.Canvas.Handle , 0 , 0 , Screen.Width , Screen.Height ,
  858.    GlobalDC , 0 , 0 , SrcCopy );
  859.   BackgroundBMP := TBitmap.Create;
  860.   BackgroundBMP.Width := 33;
  861.   BackgroundBMP.Height := 33;
  862.   New_X := TheX;
  863.   New_Y := TheY;
  864.   StoredCursor := Screen.Cursor;
  865.   Screen.Cursor := CR_NULL;
  866.   {Grab the background image}
  867.   WorkingPoint1.X := New_X - 16;
  868.   WorkingPoint1.Y := New_Y - 16;
  869.   WorkingPoint2.X := New_X + 17;
  870.   WorkingPoint2.Y := New_Y + 17;
  871.   BackgroundBmp.Canvas.CopyRect( Rect( 0 , 0 , 33 , 33 ) , WorkspaceBMP.Canvas ,
  872.      Rect( WorkingPoint1.X , WorkingPoint1.Y , WorkingPoint2.X , WorkingPoint2.Y ));
  873.   {Put the icon onto the workspace canvas}
  874.   with WorkspaceBMP.Canvas do
  875.   begin
  876.     Draw( WorkingPoint1.X , WorkingPoint1.Y , CursorIcon );
  877.   end;
  878.   {Copy the workspace bitmap onto the visible screen}
  879.     BitBlt( GlobalDC , WorkingPoint1.X , WorkingPoint1.Y , 33 , 33 ,
  880.      WorkspaceBMP.Canvas.Handle , WorkingPoint1.X , WorkingPoint1.Y , SrcCopy );
  881.   Old_X := New_X;
  882.   Old_Y := New_Y;
  883. end;
  884.  
  885. { This procedure moves the icon cursor in response to mouse moves }
  886. procedure TMouseManager.MoveIconCursor( TheX , TheY : Integer );
  887. var StartX,
  888.     StartY,
  889.     XDiff,
  890.     YDiff : Integer;
  891.     WorkingPoint1 ,
  892.     WorkingPoint2  : TPoint;
  893. begin
  894.   New_X := TheX;
  895.   New_Y := TheY;
  896.   {Put the saved bitmap onto the workspace canvas}
  897.   WorkingPoint1.X := Old_X - 16;
  898.   WorkingPoint1.Y := Old_Y - 16;
  899.   WorkingPoint2.X := Old_X + 17;
  900.   WorkingPoint2.Y := Old_Y + 17;
  901.   with WorkspaceBMP.Canvas do
  902.   begin
  903.     CopyMode := cmSrcCopy;
  904.     CopyRect( Rect( WorkingPoint1.X , WorkingPoint1.Y , WorkingPoint2.X , WorkingPoint2.Y ),
  905.       BackgroundBMP.Canvas , Rect( 0 , 0 , 33 , 33 ));
  906.   end;
  907.   {Grab the background image}
  908.   WorkingPoint1.X := New_X - 16;
  909.   WorkingPoint1.Y := New_Y - 16;
  910.   WorkingPoint2.X := New_X + 17;
  911.   WorkingPoint2.Y := New_Y + 17;
  912.   BackgroundBMP.Canvas.CopyRect( Rect( 0 , 0 , 33 , 33 ) , WorkspaceBMP.Canvas ,
  913.      Rect( WorkingPoint1.X , WorkingPoint1.Y , WorkingPoint2.X , WorkingPoint2.Y ));
  914.   {Put the icon onto the workspace canvas}
  915.   with WorkspaceBMP.Canvas do
  916.   begin
  917.     Draw( WorkingPoint1.X , WorkingPoint1.Y , CursorIcon );
  918.   end;
  919.   {Copy the workspace bitmap onto the visible screen}
  920.     if New_X > Old_X then StartX := Old_X else StartX := New_X;
  921.     if New_Y > Old_Y then StartY := Old_Y else StartY := New_Y;
  922.     XDiff := Abs( Old_X - New_X );
  923.     YDiff := Abs( Old_Y - New_Y );
  924.     {Grab the background image}
  925.     WorkingPoint1.X := StartX - 16;
  926.     WorkingPoint1.Y := StartY - 16;
  927.     BitBlt( GlobalDC , WorkingPoint1.X , WorkingPoint1.Y , 33 + XDiff , 33 + YDiff ,
  928.      WorkspaceBMP.Canvas.Handle , WorkingPoint1.X , WorkingPoint1.Y , SrcCopy );
  929.   Old_X := New_X;
  930.   Old_Y := New_Y;
  931. end;
  932.  
  933. { This procedure ends the icon cursor movement and frees its DCs }
  934. procedure TMouseManager.EndIconCursor( TheX , TheY : Integer );
  935. var WorkingPoint1 ,
  936.     WorkingPoint2 : TPoint;
  937. begin
  938.   IconCursor := false;
  939.   WorkingPoint1.X := Old_X - 16;
  940.   WorkingPoint1.Y := Old_Y - 16;
  941.   WorkingPoint2.X := Old_X + 17;
  942.   WorkingPoint2.Y := Old_Y + 17;
  943.   {Put the saved bitmap onto the workspace canvas}
  944.   with WorkspaceBMP.Canvas do
  945.   begin
  946.     CopyMode := cmSrcCopy;
  947.     CopyRect( Rect( WorkingPoint1.X , WorkingPoint1.Y , WorkingPoint2.X , WorkingPoint2.Y ),
  948.        BackGroundBMP.Canvas , Rect( 0 , 0 , 33 ,  33 ));
  949.   end;
  950.   {Copy the workspace bitmap onto the visible screen}
  951.   BitBlt( GlobalDC , WorkingPoint1.X , WorkingPoint1.Y , 33 , 33 ,
  952.    WorkspaceBMP.Canvas.handle , WorkingPoint1.X , WorkingPoint1.Y , SrcCopy );
  953.   ReleaseDC( 0 , GlobalDC );
  954.   Screen.Cursor := StoredCursor;
  955. end;
  956.  
  957. { This procedure starts the animated icon cursor }
  958. procedure TMouseManager.StartAnimatedIconCursor( TheX , TheY : Integer );
  959. begin
  960.   StartIconCursor( TheX , TheY );
  961.   TheTimer.Enabled := true;
  962.   CurrentAnimationPointer := 1;
  963. end;
  964.  
  965. { This procedue ends the animated icon cursor }
  966. procedure TMouseManager.EndAnimatedIconCursor( TheX , TheY : Integer );
  967. begin
  968.   EndIconCursor( TheX , TheY );
  969.   TheTimer.Enabled := false;
  970.   CursorIcon := TIcon( TheAnimationList[ 0 ] );
  971. end;
  972.  
  973. { This procedure moves the animated icon cursor }
  974. procedure TMouseManager.MoveAnimatedIconCursor( TheX , TheY : Integer );
  975. begin
  976.   MoveIconCursor( TheX , TheY );
  977. end;
  978.  
  979. { This procedure switches icons on timer events and prompts a redraw }
  980. procedure TMouseManager.TimerAction( Sender : TObject );
  981. begin
  982.   Inc( CurrentAnimationPointer );     
  983.   if CurrentAnimationPointer > TheAnimationList.Count then
  984.    CurrentAnimationPointer := 1;
  985.   CursorIcon := TIcon( TheAnimationList[ CurrentAnimationPointer - 1 ] );
  986.   MoveIconCursor( Old_X , Old_Y );
  987. end;
  988.  
  989. { This function returns true if CAPSLOCK is down }
  990. function TIoManager.IsCapsLockDown : Boolean;
  991. begin
  992.   if CLState then result := true else result := false;
  993. end;
  994.  
  995. { This function returns true if NUMLOCK is down }
  996. function TIoManager.ISNumLockDown : Boolean;
  997. begin
  998.   if NLState then result := true else result := false;
  999. end;
  1000.  
  1001. { This function returns true if SCROLLLOCK is down }
  1002. function TIoManager.IsScrollLockDown : Boolean;
  1003. begin
  1004.   if SLState then result := true else result := false;
  1005. end;
  1006.  
  1007. { this function gets the values for CLState, NLState, and SLState }
  1008. procedure TIoManager.InitLocks;
  1009. var TheKeys : TKeyboardState;
  1010. begin
  1011.   GetKeyBoardState( TheKeys );
  1012.   CLState := (( TheKeys[ VK_Capital ] mod 2 ) = 1 );
  1013.   NLState := (( TheKeys[ VK_Numlock ] mod 2 ) = 1 );
  1014.   CLState := (( TheKeys[ VK_Scroll ] mod 2 ) = 1 );
  1015. end;
  1016.  
  1017. { This procedure returns the state of the three lock variables }
  1018. procedure TIoManager.ReadLocks( var TheCL , TheNL , TheSL : Boolean );
  1019. begin
  1020.   TheCL := CLState;
  1021.   TheNL := NLState;
  1022.   TheSL := SLState;
  1023. end;
  1024.  
  1025. { This procedure sets the state of the three lock variables to the imported vals }
  1026. procedure TIoManager.SetLocks( TheCL , TheNL , TheSL : Boolean );
  1027. var TheKeys : TKeyBoardState;
  1028. begin
  1029.   GetKeyBoardState( TheKeys );
  1030.   CLState := TheCL;
  1031.   NLState := TheNL;
  1032.   SLState := TheSL;
  1033.   if ClState then TheKeys[ VK_Capital ] := 1 else
  1034.    TheKeys[ VK_Capital ] := 0;
  1035.   if NLState then TheKeys[ VK_Numlock ] := 1 else
  1036.    TheKeys[ VK_Numlock ] := 0;
  1037.   if SLState then TheKeys[ VK_Scroll ] := 1 else
  1038.    TheKeys[ VK_Scroll ] := 0;
  1039.   SetKeyBoardState( TheKeys );
  1040. end;
  1041.  
  1042. { This procedure handles pressing of F1 for CCFileManagerForm }
  1043. procedure TIoManager.OnF1Pressed(Sender: TObject; var Key: Word;
  1044.   Shift: TShiftState);
  1045. begin
  1046.   MessageDlg( 'Help not implemented!' , mtInformation,[mbok],0);
  1047. end;
  1048.  
  1049. { This procedure handles pressing of F2 for CCFileManagerForm }
  1050. procedure TIoManager.OnF2Pressed(Sender: TObject; var Key: Word;
  1051.   Shift: TShiftState);
  1052. begin
  1053.   TCCFileMgrForm( Parent ).BitBtn1Click( Sender );
  1054. end;
  1055.  
  1056. { This procedure handles pressing of F3 for CCFileManagerForm }
  1057. procedure TIoManager.OnF3Pressed(Sender: TObject; var Key: Word;
  1058.   Shift: TShiftState);
  1059. begin
  1060.   TCCFileMgrForm( Parent ).BitBtn2Click( Sender );
  1061. end;
  1062.  
  1063. { This procedure handles pressing of F4 for CCFileManagerForm }
  1064. procedure TIoManager.OnF4Pressed(Sender: TObject; var Key: Word;
  1065.   Shift: TShiftState);
  1066. begin
  1067.   TCCFileMgrForm( Parent ).BitBtn3Click( Sender );
  1068. end;
  1069.  
  1070. { This procedure handles pressing of F5 for CCFileManagerForm }
  1071. procedure TIoManager.OnF5Pressed(Sender: TObject; var Key: Word;
  1072.   Shift: TShiftState);
  1073. begin
  1074.   TCCFileMgrForm( Parent ).BitBtn4Click( Sender );
  1075. end;
  1076.  
  1077. { This procedure handles pressing of F6 for CCFileManagerForm }
  1078. procedure TIoManager.OnF6Pressed(Sender: TObject; var Key: Word;
  1079.   Shift: TShiftState);
  1080. begin
  1081.   TCCFileMgrForm( Parent ).BitBtn5Click( Sender );
  1082. end;
  1083.  
  1084. { This procedure handles pressing of F7 for CCFileManagerForm }
  1085. procedure TIoManager.OnF7Pressed(Sender: TObject; var Key: Word;
  1086.   Shift: TShiftState);
  1087. begin
  1088.   TCCFileMgrForm( Parent ).BitBtn9Click( Sender );
  1089. end;
  1090.  
  1091. { This procedure handles pressing of F8 for CCFileManagerForm }
  1092. procedure TIoManager.OnF8Pressed(Sender: TObject; var Key: Word;
  1093.   Shift: TShiftState);
  1094. begin
  1095.   TCCFileMgrForm( Parent ).BitBtn6Click( Sender );
  1096. end;
  1097.  
  1098. { This procedure handles pressing of F9 for CCFileManagerForm }
  1099. procedure TIoManager.OnF9Pressed(Sender: TObject; var Key: Word;
  1100.   Shift: TShiftState);
  1101. begin
  1102.   TCCFileMgrForm( Parent ).Update;
  1103. end;
  1104.  
  1105. { This procedure handles pressing of F10 for CCFileManagerForm }
  1106. procedure TIoManager.OnF10Pressed(Sender: TObject; var Key: Word;
  1107.   Shift: TShiftState);
  1108. begin
  1109.   TCCFileMgrForm( Parent ).BitBtn7Click( Sender );
  1110. end;
  1111.  
  1112. { This procedure handles pressing of F11 for CCFileManagerForm }
  1113. procedure TIoManager.OnF11Pressed(Sender: TObject; var Key: Word;
  1114.   Shift: TShiftState);
  1115. begin
  1116.   TCCFileMgrForm( Parent ).BitBtn8Click( Sender );
  1117. end;
  1118.  
  1119. { This procedure handles pressing of F12 for CCFileManagerForm }
  1120. procedure TIoManager.OnF12Pressed(Sender: TObject; var Key: Word;
  1121.   Shift: TShiftState);
  1122. begin
  1123.   TCCFileMgrForm( Parent ).BitBtn10Click( Sender );
  1124. end;
  1125.  
  1126. { Returns True if the Left Button was pressed in the last mouse operation }
  1127. function TIOManager.WasLeftPressed : Boolean;
  1128. begin
  1129.   if ( mbLeft = WhichButton ) then WasLeftPressed := true else
  1130.    WasLeftPressed := false;
  1131. end;
  1132.  
  1133. { Returns true if the Right Button was pressed in the last mouse operation }
  1134. function TIOManager.WasRightPressed : Boolean;
  1135. begin
  1136.   if mbRight = WhichButton then WasRightPressed := true else
  1137.    WasRightPressed := false;
  1138. end;
  1139.  
  1140. { Returns true if the Middle Button was pressed in the last mouse operation }
  1141. function TIOManager.WasMiddlePressed : Boolean;
  1142. begin
  1143.   if mbMiddle = WhichButton then WasMiddlePressed := true else
  1144.    WasMiddlePressed := false;
  1145. end;
  1146.  
  1147. { Returns true if the ALT key was down during the last IO operation }
  1148. function TIOManager.WasALTPressed : Boolean;
  1149. begin
  1150.   if ssAlt in WhichState then WasALTPressed := true else
  1151.    WasALTPressed := false;
  1152. end;
  1153.  
  1154. { Returns true if either SHIFT key was down during the last IO operation }
  1155. function TIOManager.WasSHIFTPressed : Boolean;
  1156. begin
  1157.   if ssShift in WhichState then WasSHIFTPressed := true else
  1158.    WasSHIFTPressed := false;
  1159. end;
  1160.  
  1161. { Returns true if the Control Key was down during the last IO operation }
  1162. function TIOManager.WasCTRLPressed : Boolean;
  1163. begin
  1164.   if ssCtrl in WhichState then WasCTRLPressed := true else
  1165.    WasCTRLPressed := false;
  1166. end;
  1167.  
  1168.  
  1169. { This procedure does a fully error-trapped change directory }
  1170. procedure TFileWorkBench.ChangeTheDirectory( NewPath : String );
  1171. var CurrentDirectory : String;
  1172. begin
  1173.   if NewPath = '..' then
  1174.   begin { Back up one level }
  1175.     {$I+}
  1176.     try
  1177.       { Find the current directory }
  1178.       GetDir( 0 , CurrentDirectory );
  1179.       { Use EFP to move up one level }
  1180.       CurrentDirectory := ExtractFilePath( CurrentDirectory );
  1181.       { Strip trailing \ if not root }
  1182.       CurrentDirectory := StripNonRootTrailingBackSlash( CurrentDirectory );
  1183.       { Try the change to the New drive }
  1184.       ChDir( CurrentDirectory );
  1185.     except
  1186.       { if any exception occurs instantiate exception and show }
  1187.       On E:EInOutError do
  1188.       begin
  1189.         { Call custom error display/lookup procedure }
  1190.         HandleIOException( EOC_CHANGEDIR , CurrentDirectory ,
  1191.          E.Message , E.ErrorCode );
  1192.       end;
  1193.     end;
  1194.   end
  1195.   else
  1196.   begin { Change to explicit path }
  1197.     {$I+}
  1198.     try
  1199.       { Get target directory path }
  1200.       CurrentDirectory := NewPath;
  1201.       { Strip trailing \ if not root }
  1202.       CurrentDirectory := StripNonRootTrailingBackSlash( CurrentDirectory );
  1203.       { Try the change to the New drive }
  1204.       ChDir( CurrentDirectory );
  1205.     except
  1206.       { if any exception occurs instantiate exception and show }
  1207.       On E:EInOutError do
  1208.       begin
  1209.         { Call custom error display/lookup procedure }
  1210.         HandleIOException( EOC_CHANGEDIR , CurrentDirectory ,
  1211.          E.Message , E.ErrorCode );
  1212.       end;
  1213.     end;
  1214.   end;
  1215. end;
  1216.  
  1217. { This procedure does a fully error-trapped change directory }
  1218. procedure TFileWorkBench.ChangeTheDriveAndDirectory( NewDrive : Integer );
  1219. var CurrentDirectory : String;
  1220. begin
  1221.   {$I+}
  1222.   try
  1223.     { Find the working directory on New drive }
  1224.     GetDir( NewDrive , CurrentDirectory );
  1225.     { Try the change to the New drive }
  1226.     ChDir( CurrentDirectory );
  1227.   except
  1228.     { if any exception occurs instantiate exception and show }
  1229.     On E:EInOutError do
  1230.     begin
  1231.       { Call custom error display/lookup procedure }
  1232.       HandleIOException( EOC_CHANGEDIR , CurrentDirectory ,
  1233.        E.Message , E.ErrorCode );
  1234.     end;
  1235.   end;
  1236. end;
  1237.  
  1238. { This procedure copies a single file with error trapping }
  1239. procedure TFileWorkBench.CopyTheFile( OldPath , NewPath : String );
  1240. var AResult : Boolean; { Internal data flag }
  1241. begin
  1242.   { If Copyfile returns false an error occurred }
  1243.   AResult := CopyFile( OldPath , NewPath +
  1244.    ExtractFileName( OldPath ));
  1245.   { Display meaningful error message }
  1246.   if not AResult then HandleDOSError( GlobalErrorType , OldPath, GlobalError );
  1247. end;
  1248.  
  1249. { This procedure moves a file by copying and delete it }
  1250. procedure TFileWorkBench.MoveTheFile( OldPath , NewPath : String );
  1251. var AResult : Boolean; { Internal data flag }
  1252.     TheFile : File;    { Use to get errors  }
  1253. begin
  1254.   { If Copyfile returns false an error occurred }
  1255.   AResult := CopyFile( OldPath , NewPath +
  1256.     ExtractFileName( OldPath ));
  1257.   { Display meaningful error message }
  1258.   if not AResult then HandleDOSError( GlobalErrorType ,
  1259.     OldPath , GlobalError );
  1260.   { After valid copying, delete source file }
  1261.   {$I+}
  1262.   if AResult then try
  1263.     { Use this trick to get valid exception handling }
  1264.     AssignFile( TheFile , OldPath );
  1265.     { Use erase because Deletefile doesn't give exceptions! }
  1266.     Erase( TheFile );
  1267.   except
  1268.     { if any exception occurs instantiate exception and show }
  1269.     On E:EInOutError do
  1270.     begin
  1271.       { Call custom error display/lookup procedure }
  1272.       HandleIOException( EOC_DELETEFILE , OldPath ,
  1273.        E.Message , E.ErrorCode );
  1274.     end;
  1275.   end;
  1276. end;
  1277.  
  1278. { This procedure safely deletes a single file }
  1279. procedure TFileWorkBench.DeleteTheFile( ThePath : String );
  1280. var TheFile : File; { Internal file handle }
  1281. begin
  1282.   {$I+}
  1283.   try
  1284.     { Use this trick to get valid exception handling }
  1285.     AssignFile( TheFile , ThePath );
  1286.     { Use erase because Deletefile doesn't give exceptions! }
  1287.     Erase( TheFile );
  1288.   except
  1289.     { if any exception occurs instantiate exception and show }
  1290.     On E:EInOutError do
  1291.     begin
  1292.       { Call custom error display/lookup procedure }
  1293.       HandleIOException( EOC_DELETEFILE , ThePath ,
  1294.        E.Message , E.ErrorCode );
  1295.     end;
  1296.   end;
  1297. end;
  1298.  
  1299. { This procedure renames a file with full error trapping }
  1300. procedure TFileWorkBench.RenameTheFile( OldPath , NewName : String );
  1301. var TheFile : File; { Internal file handle }
  1302. begin
  1303.   {$I+}
  1304.   try
  1305.     { Use this trick to get valid exception handling }
  1306.     AssignFile( TheFile , OldPath );
  1307.     { Use this because RenameFile doesn't give exceptions! }
  1308.     Rename( TheFile , NewName );
  1309.   except
  1310.     { if any exception occurs instantiate exception and show }
  1311.     On E:EInOutError do
  1312.     begin
  1313.       { Call custom error display/lookup procedure }
  1314.       HandleIOException( EOC_RENAMEFILE , OldPath  ,
  1315.        E.Message , E.ErrorCode );
  1316.     end;
  1317.   end;
  1318. end;
  1319.  
  1320. { This procedure creates a New directory with full error trapping }
  1321. procedure TFileWorkBench.CreateNewDirectory( NewPath : String );
  1322. begin
  1323.   {$I+}
  1324.   try
  1325.     Mkdir( NewPath );
  1326.   except
  1327.     { if any exception occurs instantiate exception and show }
  1328.     On E:EInOutError do
  1329.     begin
  1330.       { Call custom error display/lookup procedure }
  1331.       HandleIOException( EOC_MAKEDIR , NewPath  ,
  1332.        E.Message , E.ErrorCode );
  1333.     end;
  1334.   end;
  1335. end;
  1336.  
  1337. { This procedure remove a directory with full error trapping }
  1338. procedure TFileWorkBench.RemoveDirectory( ThePath : String );
  1339. begin
  1340.   {$I+}
  1341.   try
  1342.     Rmdir( ThePath );
  1343.   except
  1344.     { if any exception occurs instantiate exception and show }
  1345.     On E:EInOutError do
  1346.     begin
  1347.       { Call custom error display/lookup procedure }
  1348.       HandleIOException( EOC_DELETEDIR , ThePath  ,
  1349.        E.Message , E.ErrorCode );
  1350.     end;
  1351.   end;
  1352. end;
  1353.  
  1354. { Use this to set the attributes of a file with error trapping }
  1355. procedure TFileWorkBench.SetFileAttributes( TheFile  : String;
  1356.            TheAttributes : Integer );
  1357. var TheResult : Integer; { Holds error code if any }
  1358. begin
  1359.   { Attempt to set the attributes }
  1360.   TheResult := FileSetAttr( TheFile , TheAttributes );
  1361.   { if negative number error, so signal }
  1362.   if TheResult < 0 then
  1363.    HandleDOSError( EOC_SETATTR , TheFile , -TheResult );
  1364. end;
  1365.  
  1366. { This procedure recursively copies a directory to a New path }
  1367. procedure TFileWorkBench.RecursivelyCopyDirectory( OldPath , NewPath : String );
  1368. var TheDir : String; { Holds source directory }
  1369. begin
  1370.   { Get the source directory to copy }
  1371.   TheDir := ExtractFileName( OldPath );
  1372.   { Force a backslash to the Newpath variable }
  1373.   NewPath := ForceTrailingBackSlash( NewPath );
  1374.   { Add the source directory to the target path }
  1375.   NewPath := NewPath + TheDir;
  1376.   { Create a New directory with the New name }
  1377.   CreateNewDirectory( NewPath );
  1378.   { Force a backslash for compatibility }
  1379.   NewPath := FOrcetrailingBackSlash( NewPath );
  1380.   { Do the recursive call }
  1381.   HandleRecursiveAction( OldPath , NewPath , FAC_COPY );
  1382. end;
  1383.  
  1384. { This procedure recursively moves a directory tree }
  1385. procedure TFileWorkBench.RecursivelyMoveDirectory( OldPath , NewPath : String );
  1386. var TheDir    : String; { Holds source directory  }
  1387.     SavedPath : String; { Holds saved dir to kill }
  1388. begin
  1389.   { Get the source directory to move }
  1390.   TheDir := ExtractFileName( OldPath );
  1391.   { Force a backslash to the Newpath variable }
  1392.   NewPath := ForceTrailingBackSlash( NewPath );
  1393.   { Save the starting path just in case }
  1394.   SavedPath := OldPath;
  1395.   { Add the source directory to the target path }
  1396.   NewPath := NewPath + TheDir;
  1397.   { Create a New directory with the New name }
  1398.   CreateNewDirectory( NewPath );
  1399.   { Force a backslash for compatibility }
  1400.   NewPath := FOrcetrailingBackSlash( NewPath );
  1401.   { Do the recursive call }
  1402.   HandleRecursiveAction( OldPath , NewPath , FAC_MOVE );
  1403.   { Remove the source directory }
  1404.   RemoveDirectory( SavedPath );
  1405. end;
  1406.  
  1407. { This procedure handles recursively deleting an entire directory tree }
  1408. procedure TFileWorkBench.RecursivelyDeleteDirectory( ThePath : String );
  1409. begin
  1410.   HandleRecursiveAction( ThePath , '' , FAC_DELETE );
  1411. end;
  1412.  
  1413.  
  1414. { This is the generic routine to copy, move, and delete whole directory trees }
  1415. procedure TFileWorkBench.HandleRecursiveAction( StartingPath , NewPath : String;
  1416.            ActionCode : Integer );
  1417. { VITAL!!! These variables MUST be local for recursrion to work! }
  1418. var
  1419.     Finished        : Boolean;         { Loop flag              }
  1420.     TheSR           : TSearchRec;      { Searchrecord for FF/FN }
  1421.     TheResult       : Integer;         { return variable        }
  1422.     TargetPath ,
  1423.     FileMask   ,
  1424.     TheWorkingDirectory ,
  1425.     TheStoredWorkingDirectory ,
  1426.     ModifiedDirectory  : String;       { path for FF/FN         }
  1427.     TheFIP          : TFileIconPanel;  { generic FIP holder     }
  1428.     ButtonColor   ,                    { main panel color       }
  1429.     ButtonHLColor ,                    { bright panel color     }
  1430.     ButtonSColor  ,                    { dark panel color       }
  1431.     Textcolor       : TColor;          { label text color       }
  1432.     TheFile         : File;
  1433.  
  1434. begin
  1435.   { Set up the initial variables }
  1436.   Finished := false;
  1437.   TheWorkingDirectory := StartingPath;
  1438.   TheStoredWorkingDirectory := TheWorkingDirectory;
  1439.   TheWorkingDirectory := TheWorkingDirectory + '\*.*';
  1440.   TargetPath := ExtractFilePath( TheWorkingDirectory );
  1441.   { Make the call to FindFirst set to get any file }
  1442.   TheResult := FindFirst( TheWorkingDirectory , faAnyFile , TheSR );
  1443.   { loop through all files in the directory and delete them }
  1444.   while not Finished do
  1445.   begin
  1446.     { Make call to FindNext, using only SearchRecord from FindFirst }
  1447.     TheResult := FindNext( TheSR );
  1448.     { A -1 result means no more files so exit }
  1449.     if TheResult <> 0 then finished := true else
  1450.     begin
  1451.       if (( FileGetAttr( TargetPath + TheSR.Name ) and faDirectory )
  1452.        <> faDirectory ) then
  1453.       begin { A File }
  1454.         case ActionCode of
  1455.           FAC_COPY :
  1456.               begin
  1457.                 CopyTheFile( TargetPath + TheSR.Name , NewPath );
  1458.               end;
  1459.           FAC_MOVE :
  1460.               begin
  1461.                 MoveTheFile( TargetPath + TheSR.Name , NewPath );
  1462.               end;
  1463.           FAC_DELETE :
  1464.               begin { Delete }
  1465.                 if MessageDlg( 'Delete file ' + TargetPath + TheSR.Name + '?',
  1466.                    mtConfirmation , mbYesNoCancel , 0 ) = mrYes then
  1467.                     DeleteTheFile( TargetPath + TheSR.Name );
  1468.               end;
  1469.         end;
  1470.       end;
  1471.     end;
  1472.   end;
  1473.   { Set up the variables to do recursive calls on all directories}
  1474.   Finished := false;
  1475.   ModifiedDirectory := TheStoredWorkingdirectory + '\*.*';
  1476.   { Make the call to FindFirst set to get any file, ignore result }
  1477.   TheResult := FindFirst( ModifiedDirectory , faDirectory , TheSR );
  1478.   while not Finished do
  1479.   begin
  1480.     { Make call to FindNext, using only SearchRecord from FindFirst }
  1481.     TheResult := FindNext( TheSR );
  1482.     { A -1 result means no more files so exit }
  1483.     if TheResult <> 0 then
  1484.       finished := true
  1485.     else
  1486.     begin
  1487.       if TheSR.Name <> '..' then { Ignore backup in this case }
  1488.       begin
  1489.         if (( FileGetAttr( TargetPath + TheSR.Name ) and faDirectory )
  1490.          = faDirectory ) then
  1491.         begin
  1492.           { Send in the New directory name }
  1493.           ModifiedDirectory := TheStoredWorkingDirectory  + '\' +
  1494.            TheSR.Name;
  1495.           { Reproduce directory structure for recursion in copy/move }
  1496.           NewPath := NewPath + TheSR.Name;
  1497.           case ActionCode of
  1498.             FAC_COPY , FAC_MOVE :
  1499.                begin { Create ahead for move and copy }
  1500.                  { Make the New directory for moving and copying }
  1501.                  CreateNewDirectory( NewPath );
  1502.                  { Force a backslash for compatibility }
  1503.                  NewPath := ForceTrailingBackSlash( NewPath );
  1504.                end;
  1505.             FAC_DELETE :
  1506.                begin  { No prior action needed for Delete }
  1507.                end;
  1508.           end;
  1509.           { Do the recursive call }
  1510.           HandleRecursiveAction( ModifiedDirectory , NewPath , ActionCode );
  1511.           case ActionCode of
  1512.             FAC_COPY :
  1513.                begin { no action for copy }
  1514.                end;
  1515.             FAC_MOVE , FAC_DELETE :
  1516.                begin  { Delete }
  1517.                  { Get a confirmation }
  1518.                  if MessageDlg( 'Remove Directory ' + TargetPath + TheSR.Name
  1519.                   + '?', mtConfirmation , mbYesNoCancel , 0 ) = mrYes then
  1520.                    RemoveDirectory( TargetPath + TheSR.Name );
  1521.                end;
  1522.           end;
  1523.         end;
  1524.       end;
  1525.     end;
  1526.   end;
  1527. end;
  1528.  
  1529. { This is a generic copy routine taken from Delphi sample code }
  1530. { This function calls the sample Copy code and handles errors }
  1531. function TFileWorkBench.CopyFile( TargetPath ,
  1532.           DestinationPath : String ) : Boolean;
  1533. begin
  1534.   { Set global error value to no error }
  1535.   GlobalError := 0;
  1536.   { Call the sample procedure to do the copy }
  1537.   FMXUCopyFile( TargetPath, DestinationPath , GlobalErrorType , GlobalError );
  1538.   { If no error return true else return false }
  1539.   if GlobalError < 0 then CopyFile := false else
  1540.    CopyFile := true;
  1541. end;
  1542.  
  1543. { This procedure handles displaying a user-friendly Dialog box with a }
  1544. { Message for Delphi IO exception errors.                             }
  1545. procedure TFileWorkBench.HandleIOException( TheOpCode : Integer;
  1546.            ThePath : String; TheMessage : String; TheCode : Integer );
  1547. var ErrorMessageString : String;  { Holds internal data }
  1548.     OperationString    : String;  { Holds internal data }
  1549. begin
  1550.   { clear to check for unrecognized code }
  1551.   ErrorMessageString := '';
  1552.   { Check against imported code }
  1553.   case TheCode of
  1554.     2    : ErrorMessageString := 'File not found';
  1555.     3    : ErrorMessageString := 'Path not found';
  1556.     4    : ErrorMessageString := 'Too many open files';
  1557.     5    : ErrorMessageString := 'File access denied';
  1558.     6    : ErrorMessageString := 'Invalid file handle';
  1559.     12    : ErrorMessageString := 'Invalid file access code';
  1560.     15    : ErrorMessageString := 'Invalid drive number';
  1561.     16  : ErrorMessageString := 'Cannot remove current directory';
  1562.     17    : ErrorMessageString := 'Cannot rename across drives';
  1563.     100    : ErrorMessageString := 'Disk read error';
  1564.     101    : ErrorMessageString := 'Disk write error';
  1565.     102    : ErrorMessageString := 'File not assigned';
  1566.     103    : ErrorMessageString := 'File not open';
  1567.     104    : ErrorMessageString := 'File not open for input';
  1568.     105    : ErrorMessageString := 'File not open for output';
  1569.   end;
  1570.   case TheOpCode of
  1571.     EOC_CHANGEDIR : OperationString := 'Unable to Change Directory due to ';
  1572.     EOC_SOURCECOPY : OperationString := 'Unable to Copy due to Source File ';
  1573.     EOC_DESTCOPY : OperationString := 'Unable to Copy due to Destination File ';
  1574.     EOC_DELETEFILE : OperationString := 'Unable to Delete File due to ';
  1575.     EOC_DELETEDIR : OperationString := 'Unable to Delete Directory due to ';
  1576.     EOC_RENAMEFILE : OperationString := 'Unable to Rename File due to ';
  1577.     EOC_MAKEDIR : OperationString := 'Unable to Create New Directory due to ';
  1578.     EOC_SETATTR : OperationString := 'Unable to Set File Attributes due to ';
  1579.   end;
  1580.   { If not recognized use message; not a DOS error; reset cursor for neatness }
  1581.   if ErrorMessageString = '' then
  1582.   begin
  1583.     Screen.Cursor := crDefault;
  1584.     MessageDlg( OperationString + ExtractFileName( ThePath ) + ' ' +
  1585.      TheMessage , mtError , [mbOK],0);
  1586.   end
  1587.   else
  1588.   begin
  1589.     { Recognized DOS exception, reset cursor for neatness }
  1590.     Screen.Cursor := crDefault;
  1591.     MessageDlg( OperationString + ExtractFileName( ThePath ) + ' ' +
  1592.      ErrorMessageString , mtError , [mbOK], 0 );
  1593.   end;
  1594. end;
  1595.  
  1596. { This procedure handles displaying a user-friendly Dialog box with a }
  1597. { Message for DOS error codes.                                        }
  1598. procedure TFileWorkBench.HandleDOSError( TheOpCode : Integer;
  1599.            ThePath : String;  TheCode : Integer );
  1600. var ErrorMessageString : String;  { internal message holder }
  1601.     OperationString : String;     { internal message holder }
  1602. begin
  1603.   { clear the message holder to check for unrecognized code }
  1604.   ErrorMessageString := '';
  1605.   { Negate the code back to normal number and check to set string }
  1606.   case -TheCode of
  1607.     2    : ErrorMessageString := 'File not found';
  1608.     3    : ErrorMessageString := 'Path not found';
  1609.     4    : ErrorMessageString := 'Too many open files';
  1610.     5    : ErrorMessageString := 'File access denied';
  1611.     6    : ErrorMessageString := 'Invalid file handle';
  1612.     12    : ErrorMessageString := 'Invalid file access code';
  1613.     15    : ErrorMessageString := 'Invalid drive number';
  1614.     16  : ErrorMessageString := 'Cannot remove current directory';
  1615.     17    : ErrorMessageString := 'Cannot rename across drives';
  1616.     100    : ErrorMessageString := 'Disk read error';
  1617.     101    : ErrorMessageString := 'Disk write error';
  1618.     102    : ErrorMessageString := 'File not assigned';
  1619.     103    : ErrorMessageString := 'File not open';
  1620.     104    : ErrorMessageString := 'File not open for input';
  1621.     105    : ErrorMessageString := 'File not open for output';
  1622.     157 : ErrormessageString := 'Could not open Source File';
  1623.     159 : ErrormessageString := 'Could not open Target File';
  1624.   end;
  1625.   case TheOpCode of
  1626.     EOC_CHANGEDIR : OperationString := 'Unable to Change Directory due to ';
  1627.     EOC_SOURCECOPY : OperationString := 'Unable to Copy due to Source File ';
  1628.     EOC_DESTCOPY : OperationString := 'Unable to Copy due to Destination File ';
  1629.     EOC_DELETEFILE : OperationString := 'Unable to Delete File due to ';
  1630.     EOC_DELETEDIR : OperationString := 'Unable to Delete Directory due to ';
  1631.     EOC_RENAMEFILE : OperationString := 'Unable to Rename File due to ';
  1632.     EOC_MAKEDIR : OperationString := 'Unable to Create New Directory due to ';
  1633.     EOC_SETATTR : OperationString := 'Unable to Set File Attributes due to ';
  1634.   end;
  1635.   { If the string is empty an unrecognized code was sent in }
  1636.   if ErrorMessageString = '' then
  1637.   begin
  1638.     { Sent up db based on source or target error; reset cursor for neatness }
  1639.     Screen.Cursor := crDefault;
  1640.     MessageDlg( OperationString + ExtractFileName( ThePath ) + ' Error Code: ' +
  1641.      IntToStr( TheCode ) , mtError , [mbOK],0);
  1642.   end
  1643.   else  { Code is recognized, use message from case statement }
  1644.   begin
  1645.     { Format the output for source or target error }
  1646.     Screen.Cursor := crDefault;
  1647.     MessageDlg( OperationString + ExtractFileName( ThePath ) + ' ' +
  1648.      ErrorMessageString , mtError , [mbOK], 0 );
  1649.   end;
  1650. end;
  1651.  
  1652. { This procedure sets the imported booleans to the file's attributes }
  1653. procedure TFileWorkBench.GetFileAttributes( TheFile : String; var IsDirectory ,
  1654.            IsArchive , IsVolumeID , IsHidden , IsReadOnly ,
  1655.             IsSysFile : Boolean );
  1656. var TheResult : Integer; { Traps for error code on VolumeID }
  1657. begin
  1658.   { Clear the imported flags for default }
  1659.   IsDirectory := false;
  1660.   IsArchive := false;
  1661.   IsVolumeID := false;
  1662.   IsHidden := False;
  1663.   IsReadOnly := false;
  1664.   IsSysFile := false;
  1665.   { Make the Dos call }
  1666.   TheResult := FileGetAttr( TheFile );
  1667.   if TheResult < 0 then
  1668.   begin
  1669.     { Volume ID returns -2 (?) }
  1670.     IsVolumeID := true;
  1671.     { It has no other properties }
  1672.     exit;
  1673.   end;
  1674.   { Use AND test to set all other properties }
  1675.   if (( TheResult and faDirectory ) = faDirectory ) then IsDirectory := true;
  1676.   if (( TheResult and faArchive ) = faArchive ) then IsArchive := true;
  1677.   if (( TheResult and faVolumeID ) = faVolumeID ) then IsVolumeID := true;
  1678.   if (( TheResult and faReadOnly ) = faReadOnly ) then IsReadOnly := true;
  1679.   if (( TheResult and faHidden ) = faHidden ) then IsHidden := true;
  1680.   if (( TheResult and faSysFile ) = faSysFile ) then IsSysFile := true;
  1681. end;
  1682.  
  1683. { This function makes sure a pathname has a trailing \ }
  1684. function TFileWorkBench.ForceTrailingBackSlash(
  1685.           const TheFileName : String ) : String;
  1686. var TempString : String;  { Used to hold function result }
  1687. begin
  1688.   { If no trailing \ add one (root will already have one.) }
  1689.   if TheFileName[ Length( TheFileName ) ] <> '\' then
  1690.    TempString := TheFileName + '\' else TempString := TheFileName;
  1691.   { Return modified or non-modified string }
  1692.   ForceTrailingBackslash := TempString;
  1693. end;
  1694.  
  1695. { This function makes sure a non-root dir has no trailing \ }
  1696. function TFileWorkBench.StripNonRootTrailingBackSlash(
  1697.           const TheFileName : String ) : String;
  1698. var TempString : String ; { Used to hold function result }
  1699. begin
  1700.   { Default is no change }
  1701.   TempString := TheFileName;
  1702.   { If not root then }
  1703.   if Length( TheFileName ) > 3 then
  1704.   begin
  1705.     { If has a trailing backslash remove it }
  1706.     if TheFileName[ Length( TheFileName )] = '\' then
  1707.     begin
  1708.       TempString := Copy( TheFileName , 1 ,
  1709.        Length( TheFileName ) - 1 );
  1710.     end;
  1711.   end;
  1712.   { Export the final result }
  1713.   StripNonRootTrailingBackSlash := TempString;
  1714. end;
  1715.  
  1716. { This gets the next selected listbox item }
  1717. function TIconFileListBox.GetNextSelection( SourceDirectory : String;
  1718.           var CurrentItem : Integer ): String;
  1719. var TheResult : String;  { Internal storage }
  1720.     finished  : boolean; { Loop flag        }
  1721. begin
  1722.   { If out of items to check signal and exit }
  1723.   if CurrentItem > Items.Count then TheResult := '' else
  1724.   begin
  1725.     { Otherwise scan from current position till match or end }
  1726.     finished := false;
  1727.     while not finished do
  1728.     begin
  1729.       { Check against selected property }
  1730.       if Selected[ CurrentItem - 1 ] then
  1731.       begin
  1732.         { If selected then return it and abort loop }
  1733.         TheResult := SourceDirectory + Items[ CurrentItem - 1 ];
  1734.         finished := true;
  1735.         { Increment current position }
  1736.         CurrentItem := CurrentItem + 1;
  1737.      end
  1738.       else
  1739.       begin
  1740.         { Increment current position }
  1741.         CurrentItem := CurrentItem + 1;
  1742.         { Otherwise check for end of data and abort if out of entries }
  1743.         if CurrentItem > Items.Count then
  1744.         begin
  1745.           TheResult := '';
  1746.           finished := true;
  1747.         end;
  1748.       end;
  1749.     end;
  1750.   end;
  1751.   { Return stored result }
  1752.   GetNextSelection := TheResult;
  1753. end;
  1754.  
  1755. { Modified from VCL Source Copyright 1995 }
  1756. { Borland International, Inc.             }
  1757. { Use this to override display with icons }
  1758. procedure TIconFileListBox.ReadFileNames;
  1759. var
  1760.   AttrIndex   : TFileAttr;
  1761.   i           : Integer;
  1762.   FileExt     : string;
  1763.   MaskPtr     : PChar;
  1764.   Ptr         : PChar;
  1765.   AttrWord    : Word;
  1766.   TempPicture : TPicture;
  1767.   TempBmp     : TBitmap;
  1768.   TempIcon    : TIcon;
  1769. const
  1770.   Attributes: array[TFileAttr] of Word =
  1771.   ( DDL_READONLY , DDL_HIDDEN , DDL_SYSTEM , $0008 , DDL_DIRECTORY ,
  1772.     DDL_ARCHIVE  , DDL_EXCLUSIVE );
  1773. begin
  1774.   { if no handle allocated yet, this call will force         }
  1775.   { one to be allocated incorrectly (i.e. at the wrong time. }
  1776.   { In due time, one will be allocated appropriately.        }
  1777.   AttrWord := DDL_READWRITE;
  1778.   if HandleAllocated then
  1779.   begin
  1780.     { Set attribute flags based on values in FileType }
  1781.     for AttrIndex := ftReadOnly to ftArchive do
  1782.      if AttrIndex in FileType then
  1783.       AttrWord := AttrWord or Attributes[ AttrIndex ];
  1784.  
  1785.     { Use Exclusive bit to exclude normal files }
  1786.     if not ( ftNormal in FileType ) then
  1787.       AttrWord := AttrWord or DDL_EXCLUSIVE;
  1788.  
  1789.     ChDir( FDirectory ); { go to the directory we want }
  1790.     Clear;               { clear the list }
  1791.  
  1792.     GetMem( MaskPtr , 256 );
  1793.     StrPCopy( MaskPtr , FMask );
  1794.     while MaskPtr <> nil do
  1795.     begin
  1796.       Ptr := StrScan ( MaskPtr , ';' );
  1797.       if Ptr <> nil then  Ptr^ := #0;
  1798.       { build the list }
  1799.       SendMessage( Handle , LB_DIR , AttrWord , Longint( MaskPtr ));
  1800.       if Ptr <> nil then
  1801.       begin
  1802.         Ptr^ := ';';
  1803.         Inc ( Ptr );
  1804.       end;
  1805.       MaskPtr := Ptr;
  1806.     end;
  1807.     FreeMem( MaskPtr , 256 );
  1808.     { Now add the bitmaps }
  1809.     {---------------------------- begin custom code --------------------------}
  1810.     { Create the TPicture for exchange purposes }
  1811.     TempPicture := TPicture.Create;
  1812.     { Set it to icon widths }
  1813.     TempPicture.Bitmap.Width := 32;
  1814.     TempPicture.Bitmap.Height := 32;
  1815.     { Run down the list }
  1816.     for i := 0 to Items.Count - 1 do
  1817.     begin
  1818.       { Create a New temporary icon }
  1819.       TempIcon := TIcon.Create;
  1820.       { Call the custom DRWS routine to get icon for a file }
  1821.       GetIconForFile( Items[ i ] , TempIcon );
  1822.       { Put the icon on the bitmap for the picture via draw }
  1823.       { Note 1 , 1 due to bug in Draw?                      }
  1824.       TempPicture.Bitmap.Canvas.Draw( 1 , 1 , TempIcon );
  1825.       { Create a temporary bitmap }
  1826.       TempBmp := TBitmap.Create;
  1827.       { Set its width to those of the previous object's bitmaps }
  1828.       TempBmp.Width := 16;
  1829.       TempBmp.Height := 15;
  1830.       { Resize the icon's bitmap to the smaller size with stretchdraw }
  1831.       TempBmp.Canvas.StretchDraw( Rect( 1 , 1 , 15 , 14 ) ,
  1832.        TempPicture.Bitmap );
  1833.       { Set the Objects list to the bitmap }
  1834.       Items.Objects[ i ] := TempBmp;
  1835.       { Free the icon each iteration; don't free the TempBmp as list does }
  1836.       TempIcon.Free;
  1837.     end;
  1838.     { Free the TPicture exchange element }
  1839.     TempPicture.Free;
  1840.     {------------------------ end custom code --------------------------------}
  1841.     Change;
  1842.   end;
  1843. end;
  1844.  
  1845. { Use this to respond to dbl-clicking FLB filename }
  1846. procedure TIconFileListBox.TheDblClick(Sender: TObject);
  1847. begin
  1848.   { Call shellexec as a wrapper around ShellExecute API call }
  1849.   { False indicates failure, signal error                    }
  1850.   if not ShellExec( ExpandFileName( Items[ ItemIndex ] ), '' , '', false ,
  1851.    SW_SHOWNORMAL , false ) then MessageDlg('Could not Shell out to ' +
  1852.     Items[ ItemIndex ] , mtError, [mbOK], 0);
  1853. end;
  1854.  
  1855. { Create method for FIP                                }
  1856. constructor TIconFileListBox.Create( AOwner : TComponent );
  1857. begin
  1858.   { call inherited -- VITAL! }
  1859.   inherited Create( AOwner );
  1860.   { set the mouse method }
  1861.   OnDblClick := TheDblClick;
  1862. end;
  1863.  
  1864. { Create method for FIP                                }
  1865. constructor TFileIconPanel.Create( AOwner : TComponent );
  1866. begin
  1867.   { call inherited -- VITAL! }
  1868.   inherited Create( AOwner );
  1869.   { create icon and label components, making self owner/displayer }
  1870.   FTheIcon := TIcon.Create;
  1871.   FTheLabel := TLabel.Create( Self );
  1872.   FThelabel.Parent := Self;
  1873.   { Set own and labels mouse methods to stored methods }
  1874.   OnMouseUp := TheMouseUp;
  1875.   OnMouseDown := TheMouseDown;
  1876.   OnMouseMove := TheMouseMove;
  1877.   OnDragOver := TheDragOver;
  1878.   OnDragDrop := TheDragDrop;
  1879.   { Set alignment and autosize properties of the label }
  1880.   FTheLabel.Autosize := false;
  1881.   FTheLabel.Alignment := taCenter;
  1882.   { Set selected to false }
  1883.   Selected := false;
  1884. end;
  1885.  
  1886. procedure TFileIconPanel.WMLButtonDblClk(var Message: TWMLButtonDblClk);
  1887. var CurrentDirectory : String;    { Use to store dirs }
  1888.     TheDrive         : String;    { Get drive letter  }
  1889.     WhichDrive       : Integer;   { Get drive number  }
  1890.     ErrorCheck       : Integer;
  1891.     TheFWB           : TFileWorkBench;
  1892. begin
  1893.   { Create FileWorkBench for later use }
  1894.   TheFWB := TFileWorkBench.Create( Self );
  1895.   { Check for label or FIP sender }
  1896.   if FTheLabel.Caption = '..' then
  1897.   begin { deal with backup request }
  1898.     { Change to New directory }
  1899.     TheFWB.ChangeTheDirectory( '..' );
  1900.     { Call special method due to SendMessage problem! }
  1901.     TFileIconPanelScrollBox( Parent ).Update;
  1902.   end
  1903.   else
  1904.   begin
  1905.     { Check for DRIVE id in name }
  1906.     if Pos( 'DRIVE' , FTheName ) <> 0 then
  1907.     begin { Double Click on a Drive Icon }
  1908.       { Pull out the letter from name }
  1909.       TheDrive := Copy( FtheName , 7 , 1 );
  1910.       { Convert it to a number }
  1911.       WhichDrive := ( Ord( TheDrive[ 1 ] ) - Ord( 'A' )) + 1;
  1912.       TheFWB.ChangeTheDriveAndDirectory( WhichDrive );
  1913.       { Call special method due to SendMessage problem! }
  1914.       TFileIconPanelScrollBox( Parent ).Update;
  1915.     end
  1916.     else
  1917.     begin { Double click on a dir/file icon }
  1918.       if (( FileGetAttr( FTheName ) and faDirectory ) = faDirectory ) then
  1919.       begin { A directory, change to it }
  1920.         { Since full path in name, simply change to it! }
  1921.         TheFWB.ChangeTheDirectory( FTheName );
  1922.         { Call special method due to SendMessage problem! }
  1923.         TFileIconPanelScrollBox( Parent ).Update;
  1924.       end
  1925.       else
  1926.       begin { A file; attempt to shellexecute it }
  1927.         { Call shellexec as a wrapper around ShellExecute API call }
  1928.         { False indicates failure, signal error                    }
  1929.         if not ShellExec( FTheName , '' , '', false , SW_SHOWNORMAL , false )
  1930.          then MessageDlg('Could not Shell out to ' + FTheName , mtError,
  1931.           [mbOK], 0);
  1932.       end;
  1933.     end;
  1934.   end;
  1935.   TheFWB.Free; { This prevents resource leak }
  1936. end;
  1937.  
  1938. { Initialization method for FIP                                         }
  1939. procedure TFileIconPanel.Initialize( PanelX              ,
  1940.                                      PanelY              ,
  1941.                                      PanelWidth          ,
  1942.                                      PanelHeight         ,
  1943.                                      PanelBevelWidth     ,
  1944.                                      LabelFontSize         : Integer;
  1945.                                      PanelColor          ,
  1946.                                      PanelHighlightColor ,
  1947.                                      PanelShadowColor    ,
  1948.                                      LabelTextColor        : TColor;
  1949.                                      TheFilename         ,
  1950.                                      LabelFontName         : String;
  1951.                                      LabelFontStyle        : TFontStyles;
  1952.                                      ExtraData             : Integer );
  1953.  
  1954. var TheLabelHeight ,             { Holder for label pixel height }
  1955.     TheLabelWidth    : Integer;  { Holder for label pixel width  }
  1956.     TheOtherPChar    : PChar;    { Windows ASCIIZ string         }
  1957. begin
  1958.   { Set the basic properties based on imported parameters }
  1959.   Left := PanelX;
  1960.   Top := PanelY;
  1961.   Width := PanelWidth;
  1962.   Height := PanelHeight;
  1963.   Color := PanelColor;
  1964.   BevelWidth := PanelBevelWidth;
  1965.   FHighlightColor := PanelHighlightColor;
  1966.   FShadowColor := PanelShadowColor;
  1967.   FTheName := TheFilename;
  1968.   { If the ExtraData field is non-0 then a drive is being sent in }
  1969.   if ExtraData <> 0 then
  1970.   begin
  1971.     { Use the data field value to determine which icon to get from RES file }
  1972.     case ExtraData of
  1973.       1 : begin
  1974.             GetMem( TheOtherPChar , 255 );
  1975.             StrPCopy( TheOtherPChar , 'FLOPPY35' );
  1976.             FTheIcon.Handle := LoadIcon( hInstance , TheOtherPChar );
  1977.             FreeMem( TheOtherPChar , 255 );
  1978.           end;
  1979.       2 : begin
  1980.             GetMem( TheOtherPChar , 255 );
  1981.             StrPCopy( TheOtherPChar , 'FIXEDHD' );
  1982.             FTheIcon.Handle := LoadIcon( hInstance , TheOtherPChar );
  1983.             FreeMem( TheOtherPChar , 255 );
  1984.           end;
  1985.       3 : begin
  1986.             GetMem( TheOtherPChar , 255 );
  1987.             StrPCopy( TheOtherPChar , 'NETWORKHD' );
  1988.             FTheIcon.Handle := LoadIcon( hInstance , TheOtherPChar );
  1989.             FreeMem( TheOtherPChar , 255 );
  1990.           end;
  1991.       4 : begin
  1992.             GetMem( TheOtherPChar , 255 );
  1993.             StrPCopy( TheOtherPChar , 'CDROM' );
  1994.             FTheIcon.Handle := LoadIcon( hInstance , TheOtherPChar );
  1995.             FreeMem( TheOtherPChar , 255 );
  1996.           end;
  1997.       5 : begin
  1998.             GetMem( TheOtherPChar , 255 );
  1999.             StrPCopy( TheOtherPChar , 'RAM' );
  2000.             FTheIcon.Handle := LoadIcon( hInstance , TheOtherPChar );
  2001.             FreeMem( TheOtherPChar , 255 );
  2002.           end;
  2003.     end;
  2004.     { The FileNme property is already set up for the caption; use directly }
  2005.     FTheLabel.Caption := TheFilename;
  2006.     { Set up the hint for later use (make sure to set ShowHint) }
  2007.     Hint := 'Change to ' + TheFileName;
  2008.     ShowHint := true;
  2009.     { Set up all imported label properties and center it for drawing }
  2010.     with FTheLabel do
  2011.     begin
  2012.       Font.Name := LabelFontName;
  2013.       Font.Size := LabelFontSize;
  2014.       Font.Style := LabelFontStyle;
  2015.       Font.Color := LabelTextColor;
  2016.       Canvas.Brush.Color := PanelColor;
  2017.       Canvas.Font := Font;
  2018.       TheLabelHeight := Canvas.Textheight( Caption ) + 4;
  2019.       TheLabelWidth := Canvas.Textwidth( Caption ) + 4;
  2020.       Left := (( Self.Width - TheLabelWidth ) div 2 ) + 1;
  2021.       Top := ((( Round( Self.Height * 0.25 ) - 6 ) - TheLabelHeight) div 2) + 1;
  2022.       Top := Top + Round( Self.Height * 0.75 );
  2023.       Height := TheLabelHeight;
  2024.       Width := TheLabelWidth;
  2025.     end;
  2026.   end
  2027.   else
  2028.   begin
  2029.     { A file or directory has been sent in; use GetIconForFile to obtain an }
  2030.     { icon either from the file, its owner, or a RES file default.          }
  2031.     GetIconForFile( FTheName , FTheIcon );
  2032.     { Check for the Backup caption and set it specially }
  2033.     if ExtractfileName( FThename ) = '..' then
  2034.     begin
  2035.       FTheLabel.Caption := '..';
  2036.       Hint := 'Up One Level';
  2037.     end
  2038.     else
  2039.     begin
  2040.       { Otherwise just get the filename for the label caption }
  2041.       { And the full path for the hint (used later.)          }
  2042.       FTheLabel.caption := ExtractFileName( UpperCase( FTheName ));
  2043.       Hint := FTheName;
  2044.     end;
  2045.     { Activate showhint so hints are seen }
  2046.     ShowHint := true;
  2047.     { Set label properties with imported values and center for display }
  2048.     with FTheLabel do
  2049.     begin
  2050.       Font.Name := LabelFontName;
  2051.       Font.Size := LabelFontSize;
  2052.       Font.Style := LabelFontStyle;
  2053.       Font.Color := LabelTextColor;
  2054.       Canvas.Brush.Color := PanelColor;
  2055.       Canvas.Font := Font;
  2056.       TheLabelHeight := Canvas.Textheight( Caption ) + 4;
  2057.       TheLabelWidth := Canvas.Textwidth( Caption ) + 4;
  2058.       Left := (( Self.Width - TheLabelWidth ) div 2 ) + 1;
  2059.       Top := ((( Round( Self.Height * 0.25 ) - 6 ) - TheLabelHeight) div 2) + 1;
  2060.       Top := Top + Round( Self.Height * 0.75 );
  2061.       Height := TheLabelHeight;
  2062.       Width := TheLabelWidth;
  2063.     end;
  2064.   end;
  2065. end;
  2066.  
  2067. { Destroy method for FIP }
  2068. destructor TFileIconPanel.Destroy;
  2069. begin
  2070.   { free component resources }
  2071.   FTheIcon.Free;
  2072.   FTheLabel.Free;
  2073.   { call inherited -- VITAL! }
  2074.   inherited Destroy;
  2075. end;
  2076.  
  2077. { Mousedown method for FIP; used to allow dragging }
  2078. procedure TFileIconPanel.TheMouseDown(Sender: TObject;
  2079.   Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
  2080. var ThePoint , TheOtherPoint : TPoint;
  2081. begin
  2082.   { Begin a conditional drag operation (false allows timer) }
  2083.   TheIOManager.WhichButton := Button;
  2084.   TheIOManager.WhichState := Shift;
  2085.   { Currently ignore drive clicks }
  2086.   if Pos( 'DRIVE' , FTheName ) > 0 then exit;
  2087.   if (( Button = mbRight ) and ( ssShift in Shift )) then
  2088.   begin
  2089.     TheTempBitmap := TBitmap.Create;
  2090.     TheTempBitmap.Width := Self.Width;
  2091.     TheTempBitmap.Height := Self.Height;
  2092.     TheTempBitmap.Canvas.Copyrect( Rect( 0 , 0 , Self.Width , Self.Height ) ,
  2093.      Self.Canvas , Rect( 0 , 0 , Self.Width , Self.Height ));
  2094.     TheMouseManager.InitializeBitmap( TheTempBitmap );
  2095.     ThePoint.X := X;
  2096.     ThePoint.Y := Y;
  2097.     TheOtherPoint := ClientToScreen( ThePoint );
  2098.     TheMouseManager.StartBitmapCursor( TheOtherPoint.X , TheOtherPoint.Y );
  2099.     BitmapDragging := true;
  2100.     GlobalSource := Self;
  2101.     exit;
  2102.   end;
  2103.   if Button = mbRight then
  2104.   begin
  2105.     TheMouseManager.InitializeIcon( FTheIcon );
  2106.     ThePoint.X := X;
  2107.     ThePoint.Y := Y;
  2108.     TheOtherPoint := ClientToScreen( ThePoint );
  2109.     TheMouseManager.StartIconCursor( TheOtherPoint.X , TheOtherPoint.Y );
  2110.     IconDragging := true;
  2111.     GlobalSource := Self;
  2112.     exit;
  2113.   end;
  2114.   BeginDrag( false );
  2115.   { Flip status of bevels }
  2116.   if BevelOuter = bvRaised then BevelOuter := bvLowered else
  2117.    BevelOuter := bvRaised;
  2118.   { Flip selected variable }
  2119.   Selected := not Selected;
  2120.   { Set redisplay }
  2121. end;
  2122.  
  2123. procedure TFileIconPanel.TheMouseMove(Sender: TObject; Shift: TShiftState;
  2124.   X, Y: Integer);
  2125. var ThePoint, TheOtherPoint : TPoint;
  2126. begin
  2127.   if IconDragging then
  2128.   begin
  2129.     ThePoint.X := X;
  2130.     ThePoint.Y := Y;
  2131.     TheOtherPoint := ClientToScreen( ThePoint );
  2132.     TheMouseManager.MoveIconCursor( TheOtherPoint.X , TheOtherPoint.Y );
  2133.     exit;
  2134.   end;
  2135.   if BitmapDragging then
  2136.   begin
  2137.     ThePoint.X := X;
  2138.     ThePoint.Y := Y;
  2139.     TheOtherPoint := ClientToScreen( ThePoint );
  2140.     TheMouseManager.MoveBitmapCursor( TheOtherPoint.X , TheOtherPoint.Y );
  2141.     exit;
  2142.   end;
  2143. end;
  2144.  
  2145. { Mouseup Method for FIP; used to allow dragging }
  2146. procedure TFileIconPanel.TheMouseUp(Sender: TObject;
  2147.   Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
  2148. begin
  2149.   if IconDragging then
  2150.   begin
  2151.     TheMouseManager.EndIconCursor( X , Y );
  2152.     IconDragging := false;
  2153.     if GlobalSource <> Self then
  2154.     begin { Right-drag onto a panel! }
  2155.       TheDragDrop( Sender , GlobalSource , X , Y );
  2156.     end;
  2157.     exit;
  2158.   end;
  2159.   if BitmapDragging then
  2160.   begin
  2161.     TheMouseManager.EndBitmapCursor( X , Y );
  2162.     BitmapDragging := false;
  2163.     if GlobalSource <> Self then
  2164.     begin { Right-drag onto a panel! }
  2165.       TheDragDrop( Sender , GlobalSource , X , Y );
  2166.     end;
  2167.     exit;
  2168.   end;
  2169.   { End a drag operation without dropping; if dragged OK }
  2170.   { already handled.                                     }
  2171.   {EndDrag( false );}
  2172.   { If the right button is clicked, perform magic! }
  2173.   { Redisplay on general principles }
  2174.   Invalidate;
  2175. end;
  2176.  
  2177. { Use this to generically OK DnD from FIPs }
  2178. procedure TFileIconPanel.TheDragOver(Sender, Source: TObject; X,
  2179.   Y: Integer; State: TDragState; var Accept: Boolean);
  2180. begin
  2181.   { Only accept from FileIconPanel components }
  2182.   if Source is TFileIconPanel then Accept := true else Accept := false;
  2183. end;
  2184.  
  2185. { Use this to accept Drag and Drop from other FIPs }
  2186. procedure TFileIconPanel.TheDragDrop(Sender, Source: TObject; X,
  2187.   Y: Integer);
  2188. var CurrentName ,                 { Holds work name}
  2189.     TheOldString : String;        { Holds Dir      }
  2190.     TargetDir    : String;        { target of op   }
  2191.     TheResult       : Integer;    { Modal res hold }
  2192.     SourceDirectory,
  2193.     TargetDirectory,
  2194.     CurrentDirectory : String;    { Use to store dirs }
  2195.     TheDrive         : String;    { Get drive letter  }
  2196.     WhichDrive       : Integer;   { Get drive number  }
  2197.     ErrorCheck       : Integer;
  2198.     TheFWB           : TFileWorkBench;
  2199.     ThePosition : Integer;
  2200.     Finished : Boolean;
  2201.     TheFIPSB : TFileIconPanelScrollBox;
  2202. begin
  2203.   { If drop target is .. then ignore }
  2204.   if FTheLabel.Caption = '..' then exit;
  2205.   { Likewise ignore Dnd from drive icons }
  2206.   if Pos( 'DRIVE' , TFileIconPanel( Source ).FtheName ) > 0 then exit;
  2207.   { Obtain the parent of the source FIP; may not be self }
  2208.   TheFIPSB := TFileIconPanelScrollBox( TFileIconPanel( Source ).Parent );
  2209.   { Obtain source directory either as Dir or filepath }
  2210.   if (( FileGetAttr( TFileIconPanel( Source ).FTheName )
  2211.    and faDirectory ) = faDirectory ) then
  2212.   begin  { Directory; take whole path }
  2213.     SourceDirectory := TFileIconPanel( Source ).FTheName;
  2214.   end
  2215.   else
  2216.   begin { File; get pathname }
  2217.     SourceDirectory := ExtractFilePath( TFileIconPanel( Source ).FTheName );
  2218.   end;
  2219.   Sourcedirectory := TheFIPSB.TheFWB.ForceTrailingBackSlash( SourceDirectory );
  2220.   if Pos( 'DRIVE' , FTheName ) > 0 then
  2221.   begin { Drop onto a drive icon; perform action to its default dir }
  2222.     { Pull out the letter from name }
  2223.     TheDrive := Copy( FtheName , 7 , 1 );
  2224.     { Convert it to a number }
  2225.     WhichDrive := ( Ord( TheDrive[ 1 ] ) - Ord( 'A' )) + 1;
  2226.     { Determine the target directory and drive }
  2227.     GetDir( WhichDrive , TargetDirectory );
  2228.     TargetDirectory := TheFIPSB.TheFWB.ForceTrailingbackSlash( TargetDirectory );
  2229.     { Check for shift to operate on all selections }
  2230.     if TheIOManager.WasSHIFTPressed then
  2231.     begin { Operate on all selections }
  2232.       { Obtain the parent directory of the FIP dragged over }
  2233.       SourceDirectory := ExtractFilePath( TFileIconPanel( Source ).FTheName );
  2234.       SourceDirectory := TheFIPSB.TheFWB.ForceTrailingBackslash( SourceDirectory );
  2235.       { If SourceDir subset of TargetDir then abort; recursive failure }
  2236.       if Pos( SourceDirectory , TargetDirectory ) > 0 then
  2237.       begin
  2238.         MessageDlg( 'Cannot drag to same directory!',mtError,[mbOK],0 );
  2239.         exit;
  2240.       end;
  2241.       if TargetDirectory[ 1 ] <> SourceDirectory[ 1 ] then
  2242.       begin { Copy to different drives }
  2243.         if TheIOManager.WasALTPressed then
  2244.         begin { ALT overrides and does move }
  2245.           { Set up to get all current selections }
  2246.           ThePosition := 1;
  2247.           finished := false;
  2248.           while not finished do
  2249.           begin
  2250.             CurrentName := TheFIPSB.GetNextSelection( SourceDirectory ,
  2251.                    ThePosition );
  2252.             { If returns blank string then out of selections }
  2253.             if CurrentName = '' then finished := true else
  2254.             begin
  2255.               { If a directory signal error }
  2256.               if (( FileGetAttr( CurrentName ) and faDirectory ) = faDirectory ) then
  2257.               begin
  2258.                 if MessageDlg( 'Move Directory ' + CurrentName + ' to ' +
  2259.                  TargetDirectory + '?' , mtConfirmation , mbYesNoCancel , 0 ) = mrYes then
  2260.                   TheFIPSB.TheFWB.RecursivelyMoveDirectory( CurrentName ,
  2261.                    TargetDirectory );
  2262.               end
  2263.               else
  2264.               begin
  2265.                 TheFIPSB.TheFWB.MoveTheFile( CurrentName , TargetDirectory );
  2266.               end;
  2267.             end;
  2268.             { Reset to normal cursor }
  2269.             Screen.Cursor := crDefault;
  2270.           end;
  2271.         end
  2272.         else
  2273.         begin { Default is to do copy like file manager }
  2274.           { Set up to get all current selections }
  2275.           ThePosition := 1;
  2276.           finished := false;
  2277.           while not finished do
  2278.           begin
  2279.              CurrentName := TheFIPSB.GetNextSelection( SourceDirectory ,
  2280.                    ThePosition );
  2281.             { If returns blank string then out of selections }
  2282.             if CurrentName = '' then finished := true else
  2283.             begin
  2284.               { If a directory signal error }
  2285.               if (( FileGetAttr( CurrentName ) and faDirectory ) = faDirectory ) then
  2286.               begin
  2287.                 if MessageDlg( 'Copy Directory ' + CurrentName + ' to ' +
  2288.                  TargetDirectory + '?' , mtConfirmation , mbYesNoCancel , 0 ) = mrYes then
  2289.                   TheFIPSB.TheFWB.RecursivelyCopyDirectory( CurrentName ,
  2290.                    TargetDirectory );
  2291.               end
  2292.               else
  2293.               begin
  2294.                 TheFIPSB.TheFWB.CopyTheFile( CurrentName , TargetDirectory );
  2295.               end;
  2296.             end;
  2297.             { Reset to normal cursor }
  2298.             Screen.Cursor := crDefault;
  2299.           end;
  2300.         end;
  2301.       end
  2302.       else
  2303.       begin { Copy to same drive }
  2304.         if TheIOManager.WasCTRLPressed then
  2305.         begin { CTRL overrides and does copy }
  2306.           { Set up to get all current selections }
  2307.           ThePosition := 1;
  2308.           finished := false;
  2309.           while not finished do
  2310.           begin
  2311.             CurrentName := TheFIPSB.GetNextSelection( SourceDirectory ,
  2312.                    ThePosition );
  2313.             { If returns blank string then out of selections }
  2314.             if CurrentName = '' then finished := true else
  2315.             begin
  2316.               { If a directory signal error }
  2317.               if (( FileGetAttr( CurrentName ) and faDirectory ) = faDirectory ) then
  2318.               begin
  2319.                 if MessageDlg( 'Copy Directory ' + CurrentName + ' to ' +
  2320.                  TargetDirectory + '?' , mtConfirmation , mbYesNoCancel , 0 ) = mrYes then
  2321.                   TheFIPSB.TheFWB.RecursivelyCopyDirectory( CurrentName ,
  2322.                    TargetDirectory );
  2323.               end
  2324.               else
  2325.               begin
  2326.                 TheFIPSB.TheFWB.CopyTheFile( CurrentName , TargetDirectory );
  2327.               end;
  2328.             end;
  2329.             { Reset to normal cursor }
  2330.             Screen.Cursor := crDefault;
  2331.           end;
  2332.         end
  2333.         else
  2334.         begin { Default is to do move like file manager }
  2335.           { Set up to get all current selections }
  2336.           ThePosition := 1;
  2337.           finished := false;
  2338.           while not finished do
  2339.           begin
  2340.             CurrentName := TheFIPSB.GetNextSelection( SourceDirectory ,
  2341.                    ThePosition );
  2342.             { If returns blank string then out of selections }
  2343.             if CurrentName = '' then finished := true else
  2344.             begin
  2345.               { If a directory signal error }
  2346.               if (( FileGetAttr( CurrentName ) and faDirectory ) = faDirectory ) then
  2347.               begin
  2348.                 if MessageDlg( 'Move Directory ' + CurrentName + ' to ' +
  2349.                  TargetDirectory + '?' , mtConfirmation , mbYesNoCancel , 0 ) = mrYes then
  2350.                   TheFIPSB.TheFWB.RecursivelyMoveDirectory( CurrentName ,
  2351.                    TargetDirectory );
  2352.               end
  2353.               else
  2354.               begin
  2355.                 TheFIPSB.TheFWB.MoveTheFile( CurrentName , TargetDirectory );
  2356.               end;
  2357.             end;
  2358.             { Reset to normal cursor }
  2359.             Screen.Cursor := crDefault;
  2360.           end;
  2361.         end;
  2362.       end;
  2363.     end
  2364.     else
  2365.     begin { Operate on only source }
  2366.       if TargetDirectory[ 1 ] <> SourceDirectory[ 1 ] then
  2367.       begin { Copy to different drives }
  2368.         if TheIOManager.WasALTPressed then
  2369.         begin { ALT overrides and does move }
  2370.           with Source as TFileIconPanel do
  2371.           begin
  2372.             if MessageDlg( 'Move ' + FTheName + ' to ' +
  2373.              TargetDirectory + '?' , mtConfirmation , mbYesNoCancel , 0 ) = mrYes then
  2374.               TheFIPSB.TheFWB.MoveTheFile( FTheName , TargetDirectory );
  2375.           end;
  2376.         end
  2377.         else
  2378.         begin { Default is to do copy like file manager }
  2379.           with Source as TFileIconPanel do
  2380.           begin
  2381.             if MessageDlg( 'Copy ' + FTheName + ' to ' +
  2382.              TargetDirectory + '?' , mtConfirmation , mbYesNoCancel , 0 ) = mrYes then
  2383.               TheFIPSB.TheFWB.CopyTheFile( FtheName , TargetDirectory );
  2384.           end;
  2385.         end;
  2386.       end
  2387.       else
  2388.       begin { Copy to same drive }
  2389.         if TheIOManager.WasCTRLPressed then
  2390.         begin { CTRL overrides and does copy }
  2391.           with Source as TFileIconPanel do
  2392.           begin
  2393.             if MessageDlg( 'Copy ' + FTheName + ' to ' +
  2394.              TargetDirectory + '?' , mtConfirmation , mbYesNoCancel , 0 ) = mrYes then
  2395.               TheFIPSB.TheFWB.CopyTheFile( FTheName , TargetDirectory );
  2396.           end;
  2397.         end
  2398.         else
  2399.         begin { Default is to do move like file manager }
  2400.           with Source as TFileIconPanel do
  2401.           begin
  2402.             if MessageDlg( 'Move ' + FTheName + ' to ' +
  2403.              TargetDirectory + '?' , mtConfirmation , mbYesNoCancel , 0 ) = mrYes then
  2404.              TheFIPSB.TheFWB.MoveTheFile( FtheName , TargetDirectory );
  2405.           end;
  2406.         end;
  2407.       end;
  2408.     end;
  2409.   end
  2410.   else
  2411.   begin { Drop onto dir or file icon }
  2412.     if (( FileGetAttr( FTheName ) and faDirectory ) = faDirectory ) then
  2413.     begin { Drop onto a directory; use its path as target }
  2414.       TargetDirectory := FTheName;
  2415.     end
  2416.     else
  2417.     begin { Drop onto a file; use its parent as target }
  2418.       TargetDirectory := ExtractFilePath( FTheName );
  2419.     end;
  2420.     Targetdirectory := TheFIPSB.TheFWB.ForceTrailingbackslash( TargetDirectory );
  2421.     { Check for shift to operate on all selections }
  2422.     if TheIOManager.WasSHIFTPressed then
  2423.     begin { Operate on all selections }
  2424.       { Obtain the parent directory of the FIP dragged over }
  2425.       SourceDirectory := ExtractFilePath( TFileIconPanel( Source ).FTheName );
  2426.       SourceDirectory := TheFIPSB.TheFWB.ForceTrailingBackslash( SourceDirectory );
  2427.       { If SourceDir subset of TargetDir then abort; recursive failure }
  2428.       if Pos( SourceDirectory , TargetDirectory ) > 0 then
  2429.       begin
  2430.         MessageDlg( 'Cannot drag to same directory!',mtError,[mbOK],0 );
  2431.         exit;
  2432.       end;
  2433.       if TargetDirectory[ 1 ] <> SourceDirectory[ 1 ] then
  2434.       begin { Copy to different drives }
  2435.         if TheIOManager.WasALTPressed then
  2436.         begin { ALT overrides and does move }
  2437.           { Set up to get all current selections }
  2438.           ThePosition := 1;
  2439.           finished := false;
  2440.           while not finished do
  2441.           begin
  2442.              CurrentName := TheFIPSB.GetNextSelection( SourceDirectory ,
  2443.                    ThePosition );
  2444.             { If returns blank string then out of selections }
  2445.             if CurrentName = '' then finished := true else
  2446.             begin
  2447.               { If a directory signal error }
  2448.               if (( FileGetAttr( CurrentName ) and faDirectory ) = faDirectory ) then
  2449.               begin
  2450.                 if MessageDlg( 'Move Directory ' + CurrentName + ' to ' +
  2451.                  TargetDirectory + '?' , mtConfirmation , mbYesNoCancel , 0 ) = mrYes then
  2452.                   TheFIPSB.TheFWB.RecursivelyMoveDirectory( CurrentName ,
  2453.                    TargetDirectory );
  2454.               end
  2455.               else
  2456.               begin
  2457.                 TheFIPSB.TheFWB.MoveTheFile( CurrentName , TargetDirectory );
  2458.               end;
  2459.             end;
  2460.             { Reset to normal cursor }
  2461.             Screen.Cursor := crDefault;
  2462.           end;
  2463.         end
  2464.         else
  2465.         begin { Default is to do copy like file manager }
  2466.           { Set up to get all current selections }
  2467.           ThePosition := 1;
  2468.           finished := false;
  2469.           while not finished do
  2470.           begin
  2471.             CurrentName := TheFIPSB.GetNextSelection( SourceDirectory ,
  2472.                    ThePosition );
  2473.             { If returns blank string then out of selections }
  2474.             if CurrentName = '' then finished := true else
  2475.             begin
  2476.               { If a directory signal error }
  2477.               if (( FileGetAttr( CurrentName ) and faDirectory ) = faDirectory ) then
  2478.               begin
  2479.                 if MessageDlg( 'Copy Directory ' + CurrentName + ' to ' +
  2480.                  TargetDirectory + '?' , mtConfirmation , mbYesNoCancel , 0 ) = mrYes then
  2481.                   TheFIPSB.TheFWB.RecursivelyCopyDirectory( CurrentName ,
  2482.                    TargetDirectory );
  2483.               end
  2484.               else
  2485.               begin
  2486.                 TheFIPSB.TheFWB.CopyTheFile( CurrentName , TargetDirectory );
  2487.               end;
  2488.             end;
  2489.             { Reset to normal cursor }
  2490.             Screen.Cursor := crDefault;
  2491.           end;
  2492.         end;
  2493.       end
  2494.       else
  2495.       begin { Copy to same drive }
  2496.         if TheIOManager.WasCTRLPressed then
  2497.         begin { CTRL overrides and does copy }
  2498.           { Set up to get all current selections }
  2499.           ThePosition := 1;
  2500.           finished := false;
  2501.           while not finished do
  2502.           begin
  2503.             { Call generic file getting routine based on current view}
  2504.              CurrentName := TheFIPSB.GetNextSelection( SourceDirectory ,
  2505.                    ThePosition );
  2506.             { If returns blank string then out of selections }
  2507.             if CurrentName = '' then finished := true else
  2508.             begin
  2509.               { If a directory signal error }
  2510.               if (( FileGetAttr( CurrentName ) and faDirectory ) = faDirectory ) then
  2511.               begin
  2512.                 if MessageDlg( 'Copy Directory ' + CurrentName + ' to ' +
  2513.                  TargetDirectory + '?' , mtConfirmation , mbYesNoCancel , 0 ) = mrYes then
  2514.                   TheFIPSB.TheFWB.RecursivelyCopyDirectory( CurrentName ,
  2515.                    TargetDirectory );
  2516.               end
  2517.               else
  2518.               begin
  2519.                 TheFIPSB.TheFWB.CopyTheFile( CurrentName , TargetDirectory );
  2520.               end;
  2521.             end;
  2522.             { Reset to normal cursor }
  2523.             Screen.Cursor := crDefault;
  2524.           end;
  2525.         end
  2526.         else
  2527.         begin { Default is to do move like file manager }
  2528.           { Set up to get all current selections }
  2529.           ThePosition := 1;
  2530.           finished := false;
  2531.           while not finished do
  2532.           begin
  2533.             { Call generic file getting routine based on current view}
  2534.               CurrentName := TheFIPSB.GetNextSelection( SourceDirectory ,
  2535.                    ThePosition );
  2536.             { If returns blank string then out of selections }
  2537.             if CurrentName = '' then finished := true else
  2538.             begin
  2539.               { If a directory signal error }
  2540.               if (( FileGetAttr( CurrentName ) and faDirectory ) = faDirectory ) then
  2541.               begin
  2542.                 if MessageDlg( 'Move Directory ' + CurrentName + ' to ' +
  2543.                  TargetDirectory + '?' , mtConfirmation , mbYesNoCancel , 0 ) = mrYes then
  2544.                   TheFIPSB.TheFWB.RecursivelyMoveDirectory( CurrentName ,
  2545.                    TargetDirectory );
  2546.               end
  2547.               else
  2548.               begin
  2549.                 TheFIPSB.TheFWB.MoveTheFile( CurrentName , TargetDirectory );
  2550.               end;
  2551.             end;
  2552.             { Reset to normal cursor }
  2553.             Screen.Cursor := crDefault;
  2554.           end;
  2555.         end;
  2556.       end;
  2557.     end
  2558.     else
  2559.     begin { Operate on only source }
  2560.       if TargetDirectory[ 1 ] <> SourceDirectory[ 1 ] then
  2561.       begin { Copy to different drives }
  2562.         if TheIOManager.WasALTPressed then
  2563.         begin { ALT overrides and does move }
  2564.           with Source as TFileIconPanel do
  2565.           begin
  2566.             if (( FileGetAttr( FTheName ) and faDirectory ) = faDirectory ) then
  2567.             begin
  2568.               if MessageDlg( 'Move Directory ' + FTheName + ' to ' +
  2569.                TargetDirectory + '?' , mtConfirmation , mbYesNoCancel , 0 ) = mrYes then
  2570.                 TheFIPSB.TheFWB.RecursivelyMoveDirectory( FtheName ,
  2571.                  TargetDirectory );
  2572.             end
  2573.             else
  2574.             begin
  2575.               if MessageDlg( 'Move ' + FTheName + ' to ' +
  2576.                TargetDirectory + '?' , mtConfirmation , mbYesNoCancel , 0 ) = mrYes then
  2577.                 TheFIPSB.TheFWB.MoveTheFile( FTheName , TargetDirectory );
  2578.             end;
  2579.           end;
  2580.         end
  2581.         else
  2582.         begin { Default is to do copy like file manager }
  2583.           with Source as TFileIconPanel do
  2584.           begin
  2585.             if (( FileGetAttr( FTheName ) and faDirectory ) = faDirectory ) then
  2586.             begin
  2587.               if MessageDlg( 'Copy Directory ' + FtheName + ' to ' +
  2588.                TargetDirectory + '?' , mtConfirmation , mbYesNoCancel , 0 ) = mrYes then
  2589.                 TheFIPSB.TheFWB.RecursivelyCopyDirectory( FtheName ,
  2590.                  TargetDirectory );
  2591.             end
  2592.             else
  2593.             begin
  2594.               if MessageDlg( 'Copy ' + FTheName + ' to ' +
  2595.                TargetDirectory + '?' , mtConfirmation , mbYesNoCancel , 0 ) = mrYes then
  2596.                 TheFIPSB.TheFWB.CopyTheFile( FTheName , TargetDirectory );
  2597.             end;
  2598.           end;
  2599.         end;
  2600.       end
  2601.       else
  2602.       begin { Copy to same drive }
  2603.         if TheIOManager.WasCTRLPressed then
  2604.         begin { CTRL overrides and does copy }
  2605.           with Source as TFileIconPanel do
  2606.           begin
  2607.             if (( FileGetAttr( FTheName ) and faDirectory ) = faDirectory ) then
  2608.             begin
  2609.               if MessageDlg( 'Copy Directory ' + FtheName + ' to ' +
  2610.                TargetDirectory + '?' , mtConfirmation , mbYesNoCancel , 0 ) = mrYes then
  2611.                 TheFIPSB.TheFWB.RecursivelyCopyDirectory( FtheName ,
  2612.                  TargetDirectory );
  2613.             end
  2614.             else
  2615.             begin
  2616.               if MessageDlg( 'Copy ' + FTheName + ' to ' +
  2617.                TargetDirectory + '?' , mtConfirmation , mbYesNoCancel , 0 ) = mrYes then
  2618.                 TheFIPSB.TheFWB.CopyTheFile( FTheName , TargetDirectory );
  2619.             end;
  2620.           end;
  2621.         end
  2622.         else
  2623.         begin { Default is to do move like file manager }
  2624.           with Source as TFileIconPanel do
  2625.           begin
  2626.             if (( FileGetAttr( FTheName ) and faDirectory ) = faDirectory ) then
  2627.             begin
  2628.               if MessageDlg( 'Move Directory ' + FtheName + ' to ' +
  2629.                TargetDirectory + '?' , mtConfirmation , mbYesNoCancel , 0 ) = mrYes then
  2630.                 TheFIPSB.TheFWB.RecursivelyMoveDirectory( FtheName ,
  2631.                  TargetDirectory );
  2632.             end
  2633.             else
  2634.             begin
  2635.               if MessageDlg( 'Move ' + FTheName + ' to ' +
  2636.                TargetDirectory + '?' , mtConfirmation , mbYesNoCancel , 0 ) = mrYes then
  2637.                 TheFIPSB.TheFWB.MoveTheFile( FTheName , TargetDirectory );
  2638.             end;
  2639.           end;
  2640.         end;
  2641.       end;
  2642.     end;
  2643.   end;
  2644.   { Call special method due to SendMessage problem! }
  2645.   TFileIconPanelScrollBox( TFileIconPanel( Source ).Parent ).Update;
  2646.   TFileIconPanelScrollBox( Parent ).Update;
  2647. end;
  2648.  
  2649. { Paint method for FIP; overrides normal paint }
  2650. procedure TFileIconPanel.Paint;
  2651. var
  2652.   TheOtherRect   : TRect;   { Holds clientrect   }
  2653.   TopColor     ,            { Holds bright color }
  2654.   BottomColor    : TColor;  { Holds dark color   }
  2655.  
  2656. { These methods are from Borland Intl., copyright 1995 }
  2657. procedure Frame3D(    Canvas       : TCanvas;
  2658.                   var TheRect      : TRect;
  2659.                       TopColor   ,
  2660.                       BottomColor  : TColor;
  2661.                       Width        : Integer );
  2662.  
  2663. procedure DoRect;
  2664. var
  2665.   TopRight, BottomLeft: TPoint;
  2666. begin
  2667.   with Canvas, TheRect do
  2668.   begin
  2669.     TopRight.X := Right;
  2670.     TopRight.Y := Top;
  2671.     BottomLeft.X := Left;
  2672.     BottomLeft.Y := Bottom;
  2673.     Pen.Color := TopColor;
  2674.     PolyLine([BottomLeft, TopLeft, TopRight]);
  2675.     Pen.Color := BottomColor;
  2676.     Dec(BottomLeft.X);
  2677.     PolyLine([TopRight, BottomRight, BottomLeft]);
  2678.   end;
  2679. end;
  2680.  
  2681. begin
  2682.   Canvas.Pen.Width := 1;
  2683.   Dec(TheRect.Bottom); Dec(TheRect.Right);
  2684.   while Width > 0 do
  2685.   begin
  2686.     Dec(Width);
  2687.     DoRect;
  2688.     InflateRect(TheRect, -1, -1);
  2689.   end;
  2690.   Inc(TheRect.Bottom); Inc(TheRect.Right);
  2691. end;
  2692.  
  2693. procedure AdjustColors(Bevel: TPanelBevel);
  2694. begin
  2695.   TopColor := FHighlightColor;
  2696.   if Bevel = bvLowered then TopColor := FShadowColor;
  2697.   BottomColor := FShadowColor;
  2698.   if Bevel = bvLowered then BottomColor := FHighlightColor;
  2699. end;
  2700.  
  2701. { Custom code begins here }
  2702. begin
  2703.   { Get the rectangle of the control with API/method call }
  2704.   TheOtherRect := GetClientRect;
  2705.   { draw basic rectangle with basic color }
  2706.   with Canvas do
  2707.   begin
  2708.     Brush.Color := Color;
  2709.     FillRect(TheOtherRect);
  2710.   end;
  2711.   { Set up for top "icon" frame  and draw it with frame3d }
  2712.   TheOtherRect.Right := Width;
  2713.   TheOtherRect.Bottom := Round( Height * 0.75 ) - 6 ;
  2714.   if BevelOuter <> bvNone then
  2715.   begin
  2716.     AdjustColors(BevelOuter);
  2717.     Frame3D(Canvas, TheOtherRect, TopColor, BottomColor, BevelWidth);
  2718.   end;
  2719.   Frame3D(Canvas, TheOtherRect, Color, Color, BorderWidth);
  2720.   if BevelInner <> bvNone then
  2721.   begin
  2722.     AdjustColors(BevelInner);
  2723.     Frame3D(Canvas, TheOtherRect, TopColor, BottomColor, BevelWidth);
  2724.   end;
  2725.   { Do the same for the lower "label" frame }
  2726.   TheOtherRect.Top := Round( Height * 0.75 ) - 5;
  2727.   TheOtherRect.Left := 0;
  2728.   TheOtherRect.Bottom := Height;
  2729.   TheOtherRect.Right := Width;
  2730.   if BevelOuter <> bvNone then
  2731.   begin
  2732.     AdjustColors(BevelOuter);
  2733.     Frame3D(Canvas, TheOtherRect, TopColor, BottomColor, BevelWidth);
  2734.   end;
  2735.   Frame3D(Canvas, TheOtherRect, Color, Color, BorderWidth);
  2736.   if BevelInner <> bvNone then
  2737.   begin
  2738.     AdjustColors(BevelInner);
  2739.     Frame3D(Canvas, TheOtherRect, TopColor, BottomColor, BevelWidth);
  2740.   end;
  2741.   { Then draw the icon using canvas draw method }
  2742.   Canvas.Draw( (( Width - 32 ) div 2 ) + 1 ,
  2743.   ((( Round( Height * 0.75 ) - 6 ) - 32 ) div 2 ) + 1 , FTheIcon );
  2744. end;
  2745.  
  2746. { This procedure clears a scrollbox of all FileIconPanels }
  2747. procedure TFileIconPanelScrollbox.ClearTheFIPs;
  2748. var Counter_1 : Integer;
  2749.     TheComponent : TComponent;
  2750. begin
  2751.   { Note that must use while loop since component count continually }
  2752.   { decreases as removes are made!                                  }
  2753.   while ComponentCount > 0 do
  2754.   begin
  2755.     { Save the component as a generic TComponent }
  2756.     TheComponent := Components[ 0 ];
  2757.     { Call removecomponent to pull it out of the owner list for sb }
  2758.     { This avoids GPF when freeing the sb.                         }
  2759.     RemoveComponent( Components[ 0 ]);
  2760.     if ControlCount > 0 then
  2761.      RemoveControl( Controls[ 0 ] );
  2762.     { Typecast the pointer and free it to release memory and res. }
  2763.     TheParentForm.InsertComponent( TheComponent );
  2764.   end;
  2765. end;
  2766.  
  2767. { This procedure scans for drives and obtains their type and creates file }
  2768. { icon panels to represent them.                                          }
  2769. procedure TFileIconPanelScrollBox.AddDriveIcons( var XCounter ,
  2770.            YCounter : Integer );
  2771. type
  2772.   { This if from filectrl unit; reproduce here for completeness }
  2773.   TDriveType = (dtUnknown, dtNoDrive, dtFloppy, dtFixed, dtNetwork, dtCDROM,
  2774.                 dtRAM);
  2775. var
  2776.   DrivePC         : array[ 0..256] of char;
  2777.   DriveNum        : Integer;         { Used to get next drive via DOS fn   }
  2778.   IconType        : Integer;         { Used to hold icon type (defacto dt) }
  2779.   DriveChar       : Char;            { Used to hold drive letter           }
  2780.   DriveType       : TDriveType;      { Used for set-valued drive type      }
  2781.   Finished        : Boolean;         { Loop flag                           }
  2782.   TheFIP          : TFileIconPanel;  { Generic FileIconPanel variable      }
  2783.   ButtonColor   ,                    { Main panel color                    }
  2784.   ButtonHLColor ,                    { Bright panel color                  }
  2785.   ButtonSColor  ,                    { Dark panel color                    }
  2786.   Textcolor       : TColor;          { Label text color                    }
  2787.  
  2788. (*{ This code is from the FileCtrl Unit; copyright Borland Intl 1995      }
  2789. { Check whether drive is a CD-ROM.  Returns True if MSCDEX is installed }
  2790. {  and the drive is using a CD driver                                   }
  2791.  
  2792. function IsCDROM(DriveNum: Integer): Boolean; assembler;
  2793. asm
  2794.   MOV   AX,1500h { look for MSCDEX }
  2795.   XOR   BX,BX
  2796.   INT   2fh
  2797.   OR    BX,BX
  2798.   JZ    @Finish
  2799.   MOV   AX,150Bh { check for using CD driver }
  2800.   MOV   CX,DriveNum
  2801.   INT   2fh
  2802.   OR    AX,AX
  2803.   @Finish:
  2804. end;
  2805.  
  2806. { This code is from the FileCtrl Unit; copyright Borland Intl 1995      }
  2807. { Check whether drive is a RAM drive.                                   }
  2808. function IsRAMDrive(DriveNum: Integer): Boolean; assembler;
  2809. var
  2810.   TempResult: Boolean;
  2811. asm
  2812.   MOV   TempResult,False
  2813.   PUSH  DS
  2814.   MOV   BX,SS
  2815.   MOV   DS,BX
  2816.   SUB   SP,0200h
  2817.   MOV   BX,SP
  2818.   MOV   AX,DriveNum
  2819.   MOV   CX,1
  2820.   XOR   DX,DX
  2821.   INT   25h  { read boot sector }
  2822.   ADD   SP,2
  2823.   JC    @ItsNot
  2824.   MOV   BX,SP
  2825.   CMP   BYTE PTR SS:[BX+15h],0F8h  { reverify fixed disk }
  2826.   JNE   @ItsNot
  2827.   CMP   BYTE PTR SS:[BX+10h],1  { check for single FAT }
  2828.   JNE   @ItsNot
  2829.   MOV   TempResult,True
  2830.   @ItsNot:
  2831.   ADD   SP,0200h
  2832.   POP   DS
  2833.   MOV   AL, TempResult
  2834. end;
  2835.  
  2836. { This code is from the FileCtrl Unit; copyright Borland Intl 1995      }
  2837. { Finds the type of a drive letter.                                     }
  2838. function FindDriveType(DriveNum: Integer): TDriveType;
  2839. begin
  2840.   Result := TDriveType(GetDriveType(DriveNum));
  2841.   if (Result = dtFixed) or (Result = dtNetwork) then
  2842.   begin
  2843.     if IsCDROM(DriveNum) then Result := dtCDROM
  2844.     else if (Result = dtFixed) then
  2845.     begin
  2846.         { do not check for RAMDrive under Windows NT }
  2847.       if ((GetWinFlags and $4000) = 0) and IsRAMDrive(DriveNum) then
  2848.         Result := dtRAM;
  2849.     end;
  2850.   end;
  2851. end;*)
  2852.  
  2853. begin
  2854.   { Set the button colors to an aquamarine color scheme for drives }
  2855.   ButtonColor := clTeal;
  2856.   ButtonHLColor := clAqua;
  2857.   ButtonSColor := clNavy;
  2858.   TextColor := clblack;
  2859.   { Set initial variables before looping for all drives }
  2860.   finished := false;
  2861.   DriveNum := 0;
  2862.   while not finished do
  2863.   begin
  2864.     { Start with no drive found }
  2865.     IconType := 0;
  2866.     (*=============REMOVED DUE TO WINDOWS 95=========
  2867.     { Call the Borland method to get the drive info }
  2868.     DriveType := FindDriveType(DriveNum);
  2869.     ===============END WINDOWS 95 REMOVAL==========*)
  2870.     { Set its letter and make it uppercase }
  2871.     DriveChar := Chr(DriveNum + ord('a'));
  2872.     DriveChar := Upcase(DriveChar);
  2873.     StrPCopy( DrivePC , DriveChar + ':\' );
  2874.     {*&&&&&&&&&&&&&&&  WIN 95 CALL  &&&&&&&&&&&&&&&&&&&*}
  2875.     DriveType := TDriveType(GetDriveType( DrivePC ));
  2876.     { Assign an icon based on the drive type; if no drive exists type is nil }
  2877.     case DriveType of
  2878.       dtFloppy  : IconType := 1;
  2879.       dtFixed   : IconType := 2;
  2880.       dtNetwork : IconType := 3;
  2881.       dtCDROM   : IconType := 4;
  2882.       dtRAM     : IconType := 5;
  2883.     end;
  2884.     { Set to check next drive letter }
  2885.     DriveNum := DriveNum + 1;
  2886.     { But if no match then out of drives so set exit flag }
  2887.     if IconType = 0 then finished := true;
  2888.     { If drive was valid then set up the New FileIconPanel on the imported }
  2889.     { Scrollbox                                                            }
  2890.     if not finished then
  2891.     begin
  2892.       { Create the FileIconPanel and set its parent for memory mgmt and display}
  2893.       TheFIP := TFileIconPanel.Create( Self );
  2894.       TheFIP.Parent := Self;
  2895.       { Call its initialize method with imported position values and the   }
  2896.       { preset color scheme, a drive caption, and a minimum font. Note the }
  2897.       { setting of the ExtraData field to non-zero; this signals a drive   }
  2898.       { rather than a file being sent in.                                  }
  2899.       TheFIP.Initialize((( XCounter - 1 ) * TheIconSpacing ),
  2900.        (( YCounter - 1  ) * TheIconSpacing ) , TheIconSize , TheIconSize , 3 ,
  2901.         7 , ButtonColor, ButtonHLColor,
  2902.        ButtonSColor , TextColor , 'DRIVE ' + DriveChar + ':' , 'MS Serif' , [] ,
  2903.        IconType );
  2904.       { Increment the column counter; if it exceeds max move to New row      }
  2905.       { Note that these are 'var' parameters and will export final position. }
  2906.       XCounter := XCounter + 1;
  2907.       if XCounter > MaxIconsInARow then
  2908.       begin
  2909.         XCounter := 1;
  2910.         YCounter := YCounter + 1;
  2911.       end;
  2912.     end;
  2913.   end;
  2914. end;
  2915.  
  2916. { This procedure assigns colors to FIP's based on file attributes }
  2917. procedure TFileIconPanelScrollBox.GetColorsForFileIcon( TheFile : String;
  2918.            var BC , HC , SC , TC : TColor );
  2919. var AmADir      ,             { Booleans hold file attribs }
  2920.     AmAnArchive ,
  2921.     AmAVolumeId ,
  2922.     AmHidden    ,
  2923.     AmReadOnly  ,
  2924.     AmSystem      : Boolean;
  2925. begin
  2926.   { Make the call to internal fileworkbench to set attributes }
  2927.   TheFWB.GetFileAttributes( TheFile , AmADir , AmAnArchive , AmAVolumeId ,
  2928.    AmHidden , AmReadOnly , AmSystem );
  2929.   { Volume ID has no subtypes }
  2930.   if AmAVolumeID then
  2931.   begin
  2932.     BC := clOlive;
  2933.     HC := clYellow;
  2934.     SC := clBlack;
  2935.     TC := clWhite;
  2936.     exit;
  2937.   end;
  2938.   { Check all directory combinations }
  2939.   if AmADir then
  2940.   begin
  2941.     BC := clNavy;
  2942.     HC := clBlue;
  2943.     SC := clBlack;
  2944.     TC := clWhite;
  2945.     if AmHidden then
  2946.     begin
  2947.       if AmReadOnly then
  2948.       begin
  2949.         if AmSystem then
  2950.         begin { One HECK of a file! }
  2951.           BC := clBlack;
  2952.           HC := clSilver;
  2953.           SC := clGray;
  2954.           TC := clWhite;
  2955.         end
  2956.         else
  2957.         begin { Dir,RO,Hid }
  2958.           BC := clMaroon;
  2959.           HC := clFuchsia;
  2960.           SC := clGreen;
  2961.           TC := clWhite;
  2962.         end;
  2963.       end
  2964.       else
  2965.       begin { Dir,Hid }
  2966.         BC := clPurple;
  2967.         HC := clFuchsia;
  2968.         SC := clBlack;
  2969.         TC := clWhite;
  2970.       end;
  2971.     end
  2972.     else
  2973.     begin
  2974.       if AmReadOnly then
  2975.       begin
  2976.         if AmSystem then
  2977.         begin { Dir,RO,Sys }
  2978.           BC := clMaroon;
  2979.           HC := clLime;
  2980.           SC := clGreen;
  2981.           TC := clWhite;
  2982.         end
  2983.         else
  2984.         begin { Dir,RO }
  2985.           BC := clGreen;
  2986.           HC := clLime;
  2987.           SC := clBlack;
  2988.           TC := clWhite;
  2989.         end;
  2990.       end
  2991.       else
  2992.       begin
  2993.         if AmSystem then
  2994.         begin { Dir,Sys }
  2995.           BC := clMaroon;
  2996.           HC := clRed;
  2997.           SC := clBlack;
  2998.           TC := clWhite;
  2999.         end;
  3000.       end;
  3001.     end;
  3002.   end
  3003.   else { Archive Only; check all combinations }
  3004.   begin
  3005.     BC := clSilver;
  3006.     HC := clWhite;
  3007.     SC := clGray;
  3008.     TC := clBlack;
  3009.     if AmHidden then
  3010.     begin
  3011.       if AmReadOnly then
  3012.       begin
  3013.         if AmSystem then
  3014.         begin { Hid,RO,Sys }
  3015.           BC := clRed;
  3016.           HC := clLime;
  3017.           SC := clPurple;
  3018.           TC := clBlack;
  3019.         end
  3020.         else
  3021.         begin { RO,Hid }
  3022.           BC := clLime;
  3023.           HC := clFuchsia;
  3024.           SC := clMaroon;
  3025.           TC := clBlack;
  3026.         end;
  3027.       end
  3028.       else
  3029.       begin { Hid }
  3030.         BC := clFuchsia;
  3031.         HC := clWhite;
  3032.         SC := clPurple;
  3033.         TC := clBlack;
  3034.       end;
  3035.     end
  3036.     else
  3037.     begin
  3038.       if AmReadOnly then
  3039.       begin
  3040.         if AmSystem then
  3041.         begin { RO,Sys }
  3042.           BC := clRed;
  3043.           HC := clLime;
  3044.           SC := clMaroon;
  3045.           TC := clBlack;
  3046.         end
  3047.         else
  3048.         begin { RO }
  3049.           BC := clLime;
  3050.           HC := clWhite;
  3051.           SC := clGreen;
  3052.           TC := clBlack;
  3053.         end;
  3054.       end
  3055.       else
  3056.       begin
  3057.         if AmSystem then
  3058.         begin { System }
  3059.           BC := clRed;
  3060.           HC := clWhite;
  3061.           SC := clMaroon;
  3062.           TC := clBlack;
  3063.         end;
  3064.       end;
  3065.     end;
  3066.   end;
  3067. end;
  3068.  
  3069. { This procedure gets all icons for an given directory, including drives and }
  3070. { standard subdirectories. It does not get special combinations or h/ro/sys  }
  3071. procedure TFileIconPanelScrollbox.GetIconsForEntireDirectory(
  3072.             TargetPath  : String );
  3073. var Finished        : Boolean;         { Loop flag              }
  3074.     TheSR           : TSearchRec;      { Searchrecord for FF/FN }
  3075.     TheResult       : Integer;         { return variable        }
  3076.     TempPath        : String;          { path for FF/FN         }
  3077.     TheFIP          : TFileIconPanel;  { generic FIP holder     }
  3078.     RowCounter    ,                    { position in row of FIP }
  3079.     ColumnCounter   : Integer;         { position in col of FIP }
  3080.     ButtonColor   ,                    { main panel color       }
  3081.     ButtonHLColor ,                    { bright panel color     }
  3082.     ButtonSColor  ,                    { dark panel color       }
  3083.     Textcolor       : TColor;          { label text color       }
  3084.     IsADir ,                           { Variable for file attr }
  3085.     IsAnArchive ,
  3086.     IsAVolumeID,
  3087.     IsAReadOnlyFile,
  3088.     IsAHiddenFile ,
  3089.     IsASystemFile     : Boolean;
  3090.     MaxTextLength     : Integer;       { Used to safely set size}
  3091. begin
  3092.   { hide during refresh }
  3093.   Visible := false;
  3094.   { Get the icon sizes }
  3095.   TheFIP := TFileIconPanel.Create( Self );
  3096.   TheFIP.Parent := Self;
  3097.   TheFIP.FTheLabel.Canvas.Font.Name := 'MS Serif';
  3098.   TheFIP.FTheLabel.Canvas.Font.Size := 7;
  3099.   MaxTextLength := TheFIP.FTheLabel.Canvas.TextWidth( 'COMMAND.COM' );
  3100.   TheFIP.Free;
  3101.   TheIconSize := MaxTextLength + 13;
  3102.   TheIconSpacing := TheIconSize + 5;
  3103.   { Set up maximum icons per row based on screen size }
  3104.   MaxIconsInARow := ( Screen.Width div TheIconSpacing );
  3105.   { Set up the position counters }
  3106.   RowCounter := 1;
  3107.   ColumnCounter := 1;
  3108.   { Get the drives for the current machine }
  3109.   AddDriveIcons( ColumnCounter , RowCounter  );
  3110.   { Set up the initial variables }
  3111.   Finished := false;
  3112.   TempPath := TargetPath + '*.*';
  3113.   { Make the call to FindFirst set to get any file; will return '.' }
  3114.   { so discard it.                                                  }
  3115.   TheResult := FindFirst( TempPath , faAnyFile , TheSR );
  3116.   { loop through all files in the directory and look for directories }
  3117.   while not Finished do
  3118.   begin
  3119.     { Make call to FindNext, using only SearchRecord from FindFirst }
  3120.     TheResult := FindNext( TheSR );
  3121.     { A -1 result means no more files so exit }
  3122.     if TheResult <> 0 then finished := true else
  3123.     begin
  3124.       { Otherwise check for a directory attribute }
  3125.       if (( FileGetAttr( TargetPath + TheSR.Name ) and faDirectory ) =
  3126.        faDirectory ) then
  3127.       begin
  3128.         GetColorsForFileIcon( TargetPath + TheSR.Name , ButtonColor ,
  3129.          ButtonHLColor , ButtonSColor , TextColor );
  3130.         { If found create a New FileIconPanel on the imported scrollbox }
  3131.         { Note sending 0 ExtraData parameter to indicate file not drive }
  3132.         TheFIP := TFileIconPanel.Create( Self );
  3133.         TheFIP.Parent := Self;
  3134.         TheFIP.Initialize((( ColumnCounter - 1 ) * TheIconSpacing ),
  3135.          (( RowCounter - 1  ) * TheIconSpacing ) , TheIconSize, TheIconSize ,
  3136.           3 , 7 , ButtonColor, ButtonHLColor , ButtonSColor , TextColor ,
  3137.            TargetPath + TheSr.Name , 'MS Serif' , [] , 0 );
  3138.         { Increment column counter and move to New row if past limit }
  3139.         ColumnCounter := ColumnCounter + 1;
  3140.         if ColumnCounter > MaxIconsInARow then
  3141.         begin
  3142.           ColumnCounter := 1;
  3143.           RowCounter := RowCounter + 1;
  3144.         end;
  3145.       end;
  3146.     end;
  3147.   end;
  3148.   { Set up New initialization variables }
  3149.   Finished := false;
  3150.   TempPath := TargetPath + '*.*';
  3151.   { Make needed call to FindFirst and discard '.' }
  3152.   TheResult := FindFirst( TempPath , faAnyFile , TheSR );
  3153.   while not Finished do
  3154.   begin
  3155.     { Loop through file again, this time getting only archive files }
  3156.     TheResult := FindNext( TheSR );
  3157.     { Result of -1 indicates no more files }
  3158.     if TheResult <> 0 then Finished := true else
  3159.     begin
  3160.       { If faArchive file then add New FileIconPanel }
  3161.       TheFWB.GetFileAttributes(( Targetpath + TheSR.Name ) , IsADir ,
  3162.        IsAnArchive , IsAVolumeId , IsAHiddenFile , IsAReadOnlyFile ,
  3163.         IsASystemFile );
  3164.       if (( IsAnArchive ) and ( not IsADir )) then
  3165.       begin
  3166.         GetColorsForFileIcon( TargetPath + TheSR.Name , ButtonColor ,
  3167.          ButtonHLColor , ButtonSColor , TextColor );
  3168.         { Initialize New FileIconPanel and call initialize, sending 0 ED }
  3169.         TheFIP := TFileIconPanel.Create( Self );
  3170.         TheFIP.Parent := Self;
  3171.         TheFIP.Initialize((( ColumnCounter - 1 ) * TheIconSpacing ),
  3172.          (( RowCounter - 1  ) * TheIconSpacing ) , TheIconSize , TheIconSize ,
  3173.           3 , 7 , ButtonColor, ButtonHLColor , ButtonSColor , TextColor ,
  3174.            TargetPath + TheSr.Name , 'MS Serif' , [] , 0 );
  3175.         { Increment column counter and if needed row counter }
  3176.         ColumnCounter := ColumnCounter + 1;
  3177.         if ColumnCounter > MaxIconsInARow then
  3178.         begin
  3179.           ColumnCounter := 1;
  3180.           RowCounter := RowCounter + 1;
  3181.         end;
  3182.       end;
  3183.     end;
  3184.   end;
  3185.   { Reset to visible }
  3186.   Visible := true;
  3187. end;
  3188.  
  3189. { Update method for FIPscrollbox }
  3190. procedure TFileIconPanelScrollBox.Update;
  3191. begin
  3192.   IconsNeedRefreshing := true;
  3193.   { Force a repaint }
  3194.   InvalidateRect( TheStoredHandle , nil , true );
  3195. end;
  3196.  
  3197. { Create method for FIPScrollbox }
  3198. constructor TFileIconPanelScrollBox.Create( AOwner : TComponent );
  3199. begin
  3200.   inherited Create( AOwner );
  3201.   TheFWB := TFileWorkBench.Create( Self );
  3202. end;
  3203.  
  3204. { This function returns the next selected file's name }
  3205. function TFileIconPanelScrollBox.GetNextSelection( SourceDirectory : String;
  3206.                            var CurrentItem : Integer ) : String;
  3207. var TheResult    : String;      { Holds result of function }
  3208.     TheComponent : TComponent;  { Used for typecast        }
  3209.     finished     : boolean;     { Loop control variable    }
  3210.     TheComponentCount : Integer;
  3211. begin
  3212.   TheComponentCount := ComponentCount;
  3213.   { If past end of components exit with no result }
  3214.   if CurrentItem > TheComponentCount then TheResult := '' else
  3215.   begin
  3216.     { Set loop counter and run till find match or run out }
  3217.     finished := false;
  3218.     while not finished do
  3219.     begin
  3220.       { Pull component out of the list and check it }
  3221.       TheComponent := Components[ CurrentItem - 1 ];
  3222.       { Increment counter for later }
  3223.       CurrentItem := CurrentItem + 1;
  3224.       { Do the typecast with AS }
  3225.       if TheComponent is TFileIconPanel then
  3226.       with TheComponent as TFileIconPanel do
  3227.       begin
  3228.         { If its selected make sure OK }
  3229.         if Selected then
  3230.         begin
  3231.           { Don't accept backup for this level of operation }
  3232.           if FTheLabel.Caption <> '..' then
  3233.           begin
  3234.             { Otherwise return the name and abort the loop }
  3235.             TheResult := FTheName;
  3236.             finished := true;
  3237.           end;
  3238.         end
  3239.         else
  3240.         begin
  3241.           { Check to see if out of components }
  3242.           if CurrentItem > TheComponentCount then
  3243.           begin
  3244.             { If so signal error and abort }
  3245.             TheResult := '';
  3246.             finished := true;
  3247.           end;
  3248.         end;
  3249.       end;
  3250.     end;
  3251.   end;
  3252.   GetNextSelection := TheResult;
  3253. end;
  3254.  
  3255. { This procedure places a selection of files in the display based on wildcards }
  3256. procedure TFileIconPanelScrollBox.DisplayRecursiveSearchResults(
  3257.            TheStartingDirectory : String );
  3258. var XCounter ,
  3259.     YCounter   : Integer;
  3260.  
  3261. { This procedure does a recursive file search by first getting all matches (in-}
  3262. { cluding directories) and adding them to the list. Then it checks for ALL the }
  3263. { subdirectories and does the same trick on them til there are no more matches }
  3264. { and no more subdirectories, at which point it exits and recurses back up.    }
  3265. procedure RecursiveFileSearch( TheWorkingDirectory : String; var XCounter ,
  3266.                                YCounter : Integer );
  3267.  
  3268. { VITAL!!! These variables MUST be local for recursrion to work! }
  3269. var
  3270.     Finished        : Boolean;         { Loop flag              }
  3271.     TheSR           : TSearchRec;      { Searchrecord for FF/FN }
  3272.     TheResult       : Integer;         { return variable        }
  3273.     TargetPath ,
  3274.     FileMask   ,
  3275.     TheStoredWorkingDirectory ,
  3276.     ModifiedDirectory  : String;       { path for FF/FN         }
  3277.     TheFIP          : TFileIconPanel;  { generic FIP holder     }
  3278.     ButtonColor   ,                    { main panel color       }
  3279.     ButtonHLColor ,                    { bright panel color     }
  3280.     ButtonSColor  ,                    { dark panel color       }
  3281.     Textcolor       : TColor;          { label text color       }
  3282.  
  3283. begin
  3284.   { Jump out if abort pressed }
  3285.   if GlobalAbortFlag then exit;
  3286.   { Set up the initial variables }
  3287.   Finished := false;
  3288.   TheStoredWorkingDirectory := TheWorkingDirectory;
  3289.   Targetpath := ExtractFilePath( TheWorkingDirectory );
  3290.   FileMask := ExtractFileName( TheWorkingDirectory );
  3291.   { Make the call to FindFirst set to get any file }
  3292.   TheResult := FindFirst( TheWorkingDirectory , faAnyFile , TheSR );
  3293.   if TheResult < 0 then finished := true;
  3294.   if (( TheSr.Name <> '.' ) and ( TheSr.Name <> '..' ) and ( TheResult >= 0 ))
  3295.   then begin
  3296.     if (( FileGetAttr( TargetPath + TheSR.Name ) and faDirectory ) =
  3297.      faDirectory ) then
  3298.     begin { A directory }
  3299.       GetColorsForFileIcon( TargetPath + TheSR.Name , ButtonColor ,
  3300.        ButtonHLColor , ButtonSColor , TextColor );
  3301.       { If found create a New FileIconPanel on the imported scrollbox }
  3302.       { Note sending 0 ExtraData parameter to indicate file not drive }
  3303.       TheFIP := TFileIconPanel.Create( Self );
  3304.       TheFIP.Parent := Self;
  3305.       TheFIP.Initialize((( XCounter - 1 ) * TheIconSpacing ),
  3306.        (( YCounter - 1  ) * TheIconSpacing ) , TheIconSize , TheIconSize , 3 ,
  3307.         7 , ButtonColor, ButtonHLColor , ButtonSColor , TextColor , TargetPath
  3308.          + TheSr.Name , 'MS Serif' , [] , 0 );
  3309.       { Increment column counter and move to New row if past limit }
  3310.       XCounter := XCounter + 1;
  3311.       if XCounter > MaxIconsInARow then
  3312.       begin
  3313.         XCounter := 1;
  3314.         YCounter := YCounter + 1;
  3315.       end;
  3316.     end
  3317.     else
  3318.     begin { A File }
  3319.       { Set up the default color scheme for files }
  3320.       GetColorsForFileIcon( TargetPath + TheSR.Name , ButtonColor ,
  3321.        ButtonHLColor , ButtonSColor , TextColor );
  3322.       { If found create a New FileIconPanel on the imported scrollbox }
  3323.       { Note sending 0 ExtraData parameter to indicate file not drive }
  3324.       TheFIP := TFileIconPanel.Create( Self );
  3325.       TheFIP.Parent := Self;
  3326.       TheFIP.Initialize((( XCounter - 1 ) * TheIconSpacing ),
  3327.        (( YCounter - 1  ) * TheIconSpacing ) , TheIconSize, TheIconSize , 3 ,
  3328.         7 , ButtonColor, ButtonHLColor , ButtonSColor , TextColor , TargetPath
  3329.          + TheSr.Name , 'MS Serif' , [] , 0 );
  3330.       { Increment column counter and move to New row if past limit }
  3331.       XCounter := XCounter + 1;
  3332.       if XCounter > MaxIconsInARow then
  3333.       begin
  3334.         XCounter := 1;
  3335.         YCounter := YCounter + 1;
  3336.       end;
  3337.     end;
  3338.   end;
  3339.   { loop through all files in the directory and look for matches }
  3340.   while not Finished do
  3341.   begin
  3342.     { Allow keyboard processing and jump out if c-break hit }
  3343.     Application.ProcessMessages;
  3344.     if GlobalAbortFlag then exit;
  3345.     { Make call to FindNext, using only SearchRecord from FindFirst }
  3346.     TheResult := FindNext( TheSR );
  3347.     { A -1 result means no more files so exit }
  3348.     if TheResult <> 0 then finished := true else
  3349.     begin
  3350.       if (( FileGetAttr( TargetPath + TheSR.Name ) and faDirectory ) =
  3351.        faDirectory ) then
  3352.       begin { A directory }
  3353.         { Set up the blue color scheme for directories }
  3354.         GetColorsForFileIcon( TargetPath + TheSR.Name , ButtonColor ,
  3355.          ButtonHLColor , ButtonSColor , TextColor );
  3356.         { If found create a New FileIconPanel on the imported scrollbox }
  3357.         { Note sending 0 ExtraData parameter to indicate file not drive }
  3358.         TheFIP := TFileIconPanel.Create( Self );
  3359.         TheFIP.Parent := Self;
  3360.         TheFIP.Initialize((( XCounter - 1 ) * TheIconSpacing ),
  3361.          (( YCounter - 1  ) * TheIconSpacing ) , TheIconSize , TheIconSize , 3 ,
  3362.            7 , ButtonColor, ButtonHLColor , ButtonSColor , TextColor ,
  3363.             TargetPath + TheSr.Name , 'MS Serif' , [] , 0 );
  3364.         { Increment column counter and move to New row if past limit }
  3365.         XCounter := XCounter + 1;
  3366.         if XCounter > MaxIconsInARow then
  3367.         begin
  3368.           XCounter := 1;
  3369.           YCounter := YCounter + 1;
  3370.         end;
  3371.       end
  3372.       else
  3373.       begin { A File }
  3374.         { Set up the default color scheme for files }
  3375.         GetColorsForFileIcon( TargetPath + TheSR.Name , ButtonColor ,
  3376.          ButtonHLColor , ButtonSColor , TextColor );
  3377.         { If found create a New FileIconPanel on the imported scrollbox }
  3378.         { Note sending 0 ExtraData parameter to indicate file not drive }
  3379.         TheFIP := TFileIconPanel.Create( Self );
  3380.         TheFIP.Parent := Self;
  3381.         TheFIP.Initialize((( XCounter - 1 ) * TheIconSpacing ),
  3382.          (( YCounter - 1  ) * TheIconSpacing ) , TheIconSize , TheIconSize , 3 ,
  3383.           7 , ButtonColor, ButtonHLColor , ButtonSColor , TextColor ,
  3384.            TargetPath + TheSr.Name , 'MS Serif' , [] , 0 );
  3385.         { Increment column counter and move to New row if past limit }
  3386.         XCounter := XCounter + 1;
  3387.         if XCounter > MaxIconsInARow then
  3388.         begin
  3389.           XCounter := 1;
  3390.           YCounter := YCounter + 1;
  3391.         end;
  3392.       end;
  3393.     end;
  3394.   end;
  3395.   { Set up the variables to do recursive calls on all directories}
  3396.   Finished := false;
  3397.   ModifiedDirectory := ExtractFilePath( TheWorkingdirectory ) + '*.*';
  3398.   { Make the call to FindFirst set to get any file, ignore result }
  3399.   TheResult := FindFirst( ModifiedDirectory , faDirectory , TheSR );
  3400.   while not Finished do
  3401.   begin
  3402.     { Allow keyboard input and jump out if c-break hit }
  3403.     Application.ProcessMessages;
  3404.     if GlobalAbortFlag then exit;
  3405.     { Make call to FindNext, using only SearchRecord from FindFirst }
  3406.     TheResult := FindNext( TheSR );
  3407.     { A -1 result means no more files so exit }
  3408.     if TheResult <> 0 then finished := true
  3409.     else
  3410.     begin
  3411.       if TheSR.Name <> '..' then { Ignore backup in this case }
  3412.       begin
  3413.         { Do second check due to bug in FindNext }
  3414.         if (( FileGetAttr( TargetPath + TheSR.Name ) and faDirectory )
  3415.         = faDirectory ) then
  3416.         begin
  3417.           { Set up modified directory to recurse into }
  3418.           ModifiedDirectory := ExtractFilePath( TheStoredWorkingDirectory ) +
  3419.            TheSR.Name + '\' + FileMask;
  3420.           { Perform the recursion }
  3421.           RecursiveFileSearch( ModifiedDirectory , XCounter , YCounter );
  3422.         end;
  3423.       end;
  3424.     end;
  3425.   end;
  3426. end;
  3427.  
  3428. begin
  3429.   { Keep the scrollbox from updating during refresh }
  3430.   Visible := false;
  3431.   { Make the clear call }
  3432.   ClearTheFIPs;
  3433.   XCounter := 1;
  3434.   YCounter := 1;
  3435.   { Get the drives for the current machine }
  3436.   AddDriveIcons( XCounter , YCounter );
  3437.   RecursiveFileSearch( TheStartingDirectory , XCounter , YCounter );
  3438.   { Make the scrollbox visible again }
  3439.   Visible := true;
  3440. end;
  3441.  
  3442. end.
  3443.